Dear sir,
How can pass c drive with ip address using asp c#
I unable to take backup from another to my pc with different IP.
Please suggest me.
namespace backupk
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(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");
SqlConnection sqlconn = new SqlConnection(@"Data Source=10.1.246.4;Initial Catalog=DB_NTPC_MEJA_INTRANET; User ID=dba_ntpc_meja_intranet; Password=alpha$890; Connection Timeout=15;Connection Lifetime=0;Min Pool Size=0;Max Pool Size=100;Pooling=true");
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
// Backup destibation
//string backupDestination = @"C:\\SQLBackUpFolder";
//string backupDestination = @"C: \\10.1.246.4\INTERNET_DRIVE";
string backupDestination = @"E:\\10.1.246.4\Program Files\Microsoft SQL Server\MSSQL14.SQLMTPP\MSSQL\Backup";
// check if backup folder exist, otherwise create it.
if (!System.IO.Directory.Exists(backupDestination))
{
System.IO.Directory.CreateDirectory(@"C:\\10.1.246.4\\PMSSQL");
}
try
{
sqlconn.Open();
sqlcmd = new SqlCommand("backup database DB_NTPC_MEJA_INTRANET 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);
}
}
}
}