c#备份sql数据库
来源:互联网 发布:端口号哪些可以改 编辑:程序博客网 时间:2024/06/11 20:48
getSqlConnection geCon = new getSqlConnection();
SqlConnection con = geCon.GetCon();
if (con.State == ConnectionState.Open)
{
con.Close();
}
string DateStr = "Data Source=a\\a;Database=master;User id=sa;PWD=";
SqlConnection conn = new SqlConnection(DateStr);
conn.Open();
//-------------------杀掉所有连接 db_CSManage 数据库的进程--------------
string strSQL = "select spid from master..sysprocesses where dbid=db_id( 'db_CSManage') ";
SqlDataAdapter Da = new SqlDataAdapter(strSQL, conn);
DataTable spidTable = new DataTable();
Da.Fill(spidTable);
SqlCommand Cmd = new SqlCommand();
Cmd.CommandType = CommandType.Text;
Cmd.Connection = conn;
for (int iRow = 0; iRow <= spidTable.Rows.Count - 1; iRow++)
{
Cmd.CommandText = "kill " + spidTable.Rows[iRow][0].ToString(); //强行关闭用户进程
Cmd.ExecuteNonQuery();
}
conn.Close();
conn.Dispose();
//--------------------------------------------------------------------
SqlConnection sqlcon = new SqlConnection(DateStr);
sqlcon.Open();
SqlCommand sqlCmd = new SqlCommand("backup log db_CSManage to disk='" + textPaht.Text.Trim() + "' restore database db_CSManage from disk='" + textPaht.Text.Trim() + "'", sqlcon);
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
sqlcon.Close();
sqlcon.Dispose();
MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("为了必免数据丢失,在数据库还原后将关闭整个系统。");
Application.Exit();
}
else
{
MessageBox.Show("请选择备份文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
getSqlConnection geCon = new getSqlConnection();
SqlConnection con = geCon.GetCon();
string strBacl = "backup database db_CSManage to disk='" + txtPath.Text.Trim() + "\\" + txtName.Text.Trim() + ".bak'";
SqlCommand Cmd = new SqlCommand(strBacl, con);
if (Cmd.ExecuteNonQuery() != 0)
{
MessageBox.Show("数据备份成功!", "提示框", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("数据备份失败!", "提示框", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- c#备份sql数据库
- C#中备份SQL数据库
- c#备份恢复sql数据库
- c# 备份还原sql数据库
- C#实现SQL数据库备份与恢复
- C#备份和恢复SQL Server数据库
- C#备份和恢复SQL Server数据库
- C#备份和恢复SQL Server数据库
- NET C#中如何备份SQL数据库
- C# 备份还原SQL Server数据库
- C#实现SQL数据库备份与恢复
- C#实现数据库备份(以Sql Server为例)
- C#对sql数据库进行"备份"和"恢复"程序
- C#备份与恢复sql数据库的简单代码
- C# 运用SQLDMO备份和恢复Microsoft SQL Server数据库
- c#写的sql Server数据库自动备份程序
- c# 用SQLDMO 进行sql数据库备份及还原
- c#写的sql Server数据库自动备份程序
- 音轨与声道区别
- CentOS5.4(64bit)下安装配置Cacti----插件安装
- Eclipse 快捷键大全
- U-boot启动内核原理
- 注册表学习——隐藏特定的磁盘驱动器
- c#备份sql数据库
- WinRT开发语言的功能和效率
- VMware虚拟机安装MAC OS X Mountain Lion详细图文教程
- (转)redis windows下的环境搭建
- paint.setFakeBoldText(true)
- U-boot在开发板上移植过程详解--bootloader架构分析
- BIT寒假练习-2013__1006:The most frequent number
- h264码流rtp打包(一)
- Apache与Tomcat的3种连接方式分析