C#中备份数据库
privatevoidBackupDatabase(){DateTimedt=DateTime.Now;stringdayName=dt.Day.ToString()+"...
private void BackupDatabase()
{
DateTime dt = DateTime.Now;
string dayName = dt.Day.ToString() + "日";
string dayPath = databaseSavePath + "\\" + dayName;
if(!Directory.Exists(dayPath))
{
Directory.CreateDirectory(dayPath);
}
string dirName = string.Format(@"{0}\{1}.bak", dayPath, dayName);//保存的文件名
BACKUP DATABASE HJ_ABDoor to disk = @dirName;
// string strSQL = string.Format(@"BACKUP DATABASE ABDoor to disk = '{0}'", dirName);
//SQLServer.SQLInquiry(strSQL);
}
不行,这个程序有什么问题?求高手指教 展开
{
DateTime dt = DateTime.Now;
string dayName = dt.Day.ToString() + "日";
string dayPath = databaseSavePath + "\\" + dayName;
if(!Directory.Exists(dayPath))
{
Directory.CreateDirectory(dayPath);
}
string dirName = string.Format(@"{0}\{1}.bak", dayPath, dayName);//保存的文件名
BACKUP DATABASE HJ_ABDoor to disk = @dirName;
// string strSQL = string.Format(@"BACKUP DATABASE ABDoor to disk = '{0}'", dirName);
//SQLServer.SQLInquiry(strSQL);
}
不行,这个程序有什么问题?求高手指教 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
///
///备份方法
///
SqlConnection conn = new SqlConnection("Server=.;Database=master;User ID=sa;Password=sa;");
SqlCommand cmdBK = new SqlCommand();
cmdBK.CommandType = CommandType.Text;
cmdBK.Connection = conn;
cmdBK.CommandText = @"backup database test to disk='C:\ba' with init";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
MessageBox.Show("Backup successed.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
///备份方法
///
SqlConnection conn = new SqlConnection("Server=.;Database=master;User ID=sa;Password=sa;");
SqlCommand cmdBK = new SqlCommand();
cmdBK.CommandType = CommandType.Text;
cmdBK.Connection = conn;
cmdBK.CommandText = @"backup database test to disk='C:\ba' with init";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
MessageBox.Show("Backup successed.");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询