还原数据库时出错 [英] Error in Restoring Database

查看:92
本文介绍了还原数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了两个按钮,一个用于备份,另一个用于还原


I have used two buttons one for Backup and other for Restore


private void button1_Click(object sender, EventArgs e)
{
            con = new SqlConnection("Data Source = localhost; Initial Catalog=master ;Integrated Security = True;");
            con.Open();
            if (con.State == ConnectionState.Closed)
                con.Open();
            string qry = "Restore  database Peshawar_Children_Academy_Database from Disk= ''F:\\My.bak''";
            com = new SqlCommand("use master", con);
            com.ExecuteNonQuery();
            com = new SqlCommand(qry, con);
            com.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("Has been restored database", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button2_Click(object sender, EventArgs e)
 {
            con = new SqlConnection("Data Source=localhost;Initial Catalog=Peshawar_Children_Academy_DataBase;Integrated Security = True;");
            con.Open();
            string qry = "backup database Peshawar_Children_Academy_Database to disk =''F:\\My.bak'' with init,stats=10";
            com = new SqlCommand(qry, con);
            com.ExecuteNonQuery();
            
            con.Close();
            con.Dispose();
            MessageBox.Show("The support of the database was successfully performed", "Back", MessageBoxButtons.OK, MessageBoxIcon.Information);
}



问题是当我单击第一个还原"按钮时,数据库恢复已成功进行,但是如果我单击第一个备份"按钮,然后单击还原"按钮,则会收到以下错误消息.
请帮助我,并尽快提供更好的姿态..谢谢
消息:
由于正在使用数据库,因此无法获得独占访问.
还原数据库异常终止.



Problem is when I click 1st Restore button then Restoration of Database has taken successfully but if I click 1st backup button and then click on Restore button then I got the following error Message.
Kindly help me and provide a better soution as soon as possible..Thanks
Message:
Exclusive access could not be obtained because the database is in use.
RESTORE DATABASE is terminating abnormally.

推荐答案

在开始还原之前,备份是否已完成?
这可能就是为什么您收到此错误消息的原因.
Has your backup completed before you start a restore?
This could be why you are getting this error message.


这篇关于还原数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆