Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1010: Newline in constant Source Error:
|
Line 45: {
Line 46: sqlconn.Open();
Line 47: sqlcmd = new SqlCommand("backup database TutorialsPanel to disk='" + backupDestination + "\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlconn);
Line 48: sqlcmd.ExecuteNonQuery();
Line 49: //Close connection
|
namespace sql_backup
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection sqlconn = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Cascading_ddl;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnBackup_Click(object sender, EventArgs e)
{
SqlConnection sqlconn = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Cascading_ddl;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
// Backup destibation
string backupDestination = @"C:\SQLBackUpFolder";
// check if backup folder exist, otherwise create it.
if (!System.IO.Directory.Exists(backupDestination))
{
System.IO.Directory.CreateDirectory(@"D:\SQLBackUpFolder");
}
try
{
sqlconn.Open();
sqlcmd = new SqlCommand("backup database TutorialsPanel to disk='" + backupDestination + "\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlconn);
sqlcmd.ExecuteNonQuery();
//Close connection
sqlconn.Close();
Response.Write("Backup database successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}