当我尝试恢复备份数据库时,它会成功恢复数据库,但是当注销系统时,它会给出异常“将请求发送到服务器时发生传输级别错误。(提供程序:共享内存提供程序,错误0-管道的另一端没有过程)“......如何解决这个问题 我恢复数据库的代码是:
private void restoreBtn_Click(object sender, EventArgs e)
{
string database = cn.Database.ToString();
try
{
cn.Open();
string sqlres1=string.Format("ALTER DATABASE ["+database+"] SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
SqlCommand command1=new SqlCommand(sqlres1,cn);
command1.ExecuteNonQuery();
string sqlres2 = "USE MASTER RESTORE DATABASE ["+database+"] FROM DISK='"+restoretxt.Text+"' WITH REPLACE";
SqlCommand command2 = new SqlCommand(sqlres2, cn);
command2.ExecuteNonQuery();
string sqlres3 = string.Format("ALTER DATABASE [" + database + "] SET MULTI_USER");
SqlCommand command3 = new SqlCommand(sqlres3, cn);
command3.ExecuteNonQuery();
MessageBox.Show("Database restore done successfully");
this.Close();
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
}