C# 备份数据库

            try
{
string strg = Application.StartupPath.ToString();
strg
= strg.Substring(0, strg.LastIndexOf("\\"));
strg
= strg.Substring(0, strg.LastIndexOf("\\"));
strg
+= @"\Data";
string sqltxt = @"BACKUP DATABASE db_MrCy TO Disk='" + strg + "\\" + txtpath.Text +".bak"+ "'";
SqlConnection conn
= BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd
= new SqlCommand(sqltxt, conn);
cmd.ExecuteNonQuery();
conn.Close();
if (MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

  

posted @ 2011-08-04 15:55  许明吉博客  阅读(346)  评论(0编辑  收藏  举报