Sunday, August 30, 2009

How to Backup SQL Server Database Programatically in C#

SqlConnection SC = new SqlConnection("Place your connection string here");
string sqltxt ="";
string ipath ="C:\Backup.Bak";
sqltxt = @"BACKUP DATABASE SampleDB TO DISK = ' " + ipath + "' WITH INIT ";
 
 
SqlCommand sqlCm = new SqlCommand(sqltxt, SC);
SC.Open();
sqlCm.ExecuteNonQuery();
SC.Close();
Post a Comment