当我不能获得数据库备份时如何解决此错误...帮助我 [英] How Can I Solve This Error When I Wont Get Backup Of Database ... Help Me

查看:112
本文介绍了当我不能获得数据库备份时如何解决此错误...帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法打开备份设备'I:\ aaa.bak'。操作系统错误32(进程无法访问该文件,因为它正由另一个进程使用。)



这里我的代码



private void button_backup_Click(object sender,EventArgs e)

{

// con是连接字符串

con .Open();

string str =USE TestDB;;

string str1 =BACKUP DATABASE TestDB TO DISK ='E:\ backupfile.Bak'WITH FORMAT,MEDIANAME ='Z_SQLServerBackups',NAME ='Testdb的完全备份';;

SqlCommand cmd1 = new SqlCommand(str,con);

SqlCommand cmd2 = new SqlCommand(str1,con);

cmd1.ExecuteNonQuery();

cmd2.ExecuteNonQuery();

MessageBox.Show(成功 );

con.Close();

}

Cannot open backup device 'I:\aaa.bak'. Operating system error 32(The process cannot access the file because it is being used by another process.).

here my code

private void button_backup_Click(object sender, EventArgs e)
{
//con is the connection string
con.Open();
string str = "USE TestDB;";
string str1="BACKUP DATABASE TestDB TO DISK = 'E:\backupfile.Bak' WITH FORMAT,MEDIANAME = 'Z_SQLServerBackups',NAME = 'Full Backup of Testdb';";
SqlCommand cmd1 = new SqlCommand(str, con);
SqlCommand cmd2 = new SqlCommand(str1, con);
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
MessageBox.Show("success");
con.Close();
}

推荐答案

数据库恢复很复杂:因为它破坏了数据库的当前内容。



在这种情况下,我猜测你的备份代码是错误的,并且正在保持文件打开 - 这将解释您正在获得的正在使用的文件错误,其他几乎没有。



查看您的备份代码,以及彻底检查:然后尝试使用恢复。

这里有一个如何进行备份的示例:用C#备份SQL数据库 [ ^ ]这可能会对你有帮助。
Database restoration is complex: because it destroys the current content of the DB.

In this case, I'd hazard a guess that your backup code is wrong, and is holding the file open - that would explain the "file in use" error you are getting, where very little else would.

Look at your backup code, and check it thoroughly: then try to use the restore.
There is an example of how I take backups here: Backing up an SQL Database in C#[^] which may help you.


这篇关于当我不能获得数据库备份时如何解决此错误...帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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