简体   繁体   English

数据库备份错误

[英]Database backup error

I have this code snippet that creates backup of db: 我有这个代码片段创建db的备份:

try
{
  string connStr = "<valid connection string>";

  using (SqlConnection conn = new SqlConnection(connStr))
  {
    conn.Open();

    string sqlStmt = String.Format("BACKUP DATABASE InventoryDB TO DISK='{0}'", 
                                      DBBackupSaveFileDialog.FileName);

    using (SqlCommand bu2 = new SqlCommand(sqlStmt, conn))
    {
      bu2.ExecuteNonQuery();
    }
...

problem is that it works fine on developer pc but when i try on different machine it will give this error 问题是它在开发人员电脑上工作正常但是当我尝试在不同的机器上它会给出这个错误

Cannot open backup device 'C:\\User\\Saleh\\Documents\\12.bak'. 无法打开备份设备'C:\\ User \\ Saleh \\ Documents \\ 12.bak'。 Operating system error 5 (failed to rerieve text for this error. Reason: 15105). 操作系统错误5(无法恢复此错误的文本。原因:15105)。

You need to make sure the SQL Server service account has write access to C:\\Users\\Saleh\\ 您需要确保SQL Server服务帐户具有对C:\\Users\\Saleh\\写入权限

First, see what account SQL Server is running as. 首先,查看SQL Server正在运行的帐户。 Control Panel > Administrative Tools > Services, right-click the relevant SQL Server service, hit Properties, and see the account listed on the Log On tab. “控制面板”>“管理工具”>“服务”,右键单击相关的SQL Server服务,单击“属性”,然后查看“登录”选项卡上列出的帐户。 Now go to Windows Explorer, right-click the folder, hit Properties, and on the Security tab, you can add this user account to the list, and make sure they have write access. 现在转到Windows资源管理器,右键单击该文件夹,单击“属性”,然后在“安全”选项卡上,可以将此用户帐户添加到列表中,并确保它们具有写入权限。 If you have further problems with this, your question should probably to to superuser.com as it's becoming a Windows / permissions problem, not a programming one. 如果您对此有进一步的问题,您的问题可能应该是superuser.com,因为它正在成为Windows /权限问题,而不是编程问题。

Better yet, stop running backups to user folders - use SQL Server's backup folder, which SQL Server already has permissions to write to. 更好的是,停止向用户文件夹运行备份 - 使用SQL Server的备份文件夹,SQL Server已有权写入该文件夹。 If you need to move it later, do that separately. 如果您以后需要移动它,请单独执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM