SQL 数据库备份有关问题
SQL 数据库备份问题
如题。
我使用以下的代码来恢复数据库(txtDRPath存放待恢复的文件路径名):
if (MessageBox.Show("您确认开始数据还原吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
try
{
ReStore("db_Wong", txtDRPath.Text);
MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtDRPath.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
void ReStore(string dbname, string FileRestoreName)
{
int i = this.RunProc("use master RESTORE DATABASE " + dbname + " from DISK='" + FileRestoreName + "'");
}
运行后老是提示:'因为数据库正在使用,所以未能获得对数据库的独占......',请问该如何修改代码来解决?谢谢!
------解决思路----------------------
其它程序正在引用那个数据库文件,这不是程序能解决的问题了,你先把那个文件的占用程序关了
如题。
我使用以下的代码来恢复数据库(txtDRPath存放待恢复的文件路径名):
if (MessageBox.Show("您确认开始数据还原吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
try
{
ReStore("db_Wong", txtDRPath.Text);
MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtDRPath.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
void ReStore(string dbname, string FileRestoreName)
{
int i = this.RunProc("use master RESTORE DATABASE " + dbname + " from DISK='" + FileRestoreName + "'");
}
运行后老是提示:'因为数据库正在使用,所以未能获得对数据库的独占......',请问该如何修改代码来解决?谢谢!
------解决思路----------------------
其它程序正在引用那个数据库文件,这不是程序能解决的问题了,你先把那个文件的占用程序关了