string dbpath= System.Windows.Forms.Application.StartupPath;
string dbp = dbpath + "\\MyDatabase.Mdf";
SqlCommand cmd = new SqlCommand("backup database ['"+dbp+"'] to disk ='d:\\svBackUp1.bak' with init,stats=10",con);
cmd.ExecuteNonQuery();
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Error was that "The identifier start with---- is too long. Maximum length is 128" so I Make the "MyDatabase.mdf" with small Name "MyDb.mdf".So the identifier becomes less than 128.
My code is
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NewConnectionString"].ConnectionString);
{
con.Open();
string DatabaseName = Application.StartupPath + @"\MyDb.mdf";
SqlCommand cmd = new SqlCommand("BACKUP DATABASE ["+DatabaseName+"] to DISK='D:\\MyBackup.bak' ", con);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Success");
}
catch (Exception Ex){
MessageBox.Show("'"+Ex.ToString()+"'");
}
con.Close();
}
successfully take the Backup