备份文件夹问题

本文关键字:问题 文件夹 备份文件 备份 | 更新日期: 2023-09-27 18:18:51

当运行下面的代码时,我一直得到"访问被拒绝",但我对文件夹有完全的管理权限。

{"Cannot open backup device '''''networkDrive'backups'''. Operating system error 5(Access is denied.).'r'nBACKUP DATABASE is terminating abnormally."}

文件夹目标是@"'networkDrive'backups";

我也试过@ '"C: '备份"和@"C: '备份"

    private static string publicConString = "server=myServer;Trusted_Connection=Yes;persist security info=False;connection timeout=120";
    public static void BackupDatabase(String databaseName, String userName, String password, String serverName, String destinationPath)
    {
        Backup sqlBackup = new Backup();
        sqlBackup.Action = BackupActionType.Database;
        sqlBackup.BackupSetDescription = "ArchiveDataBase:" +
                                         DateTime.Now.ToShortDateString();
        sqlBackup.BackupSetName = "Archive";
        sqlBackup.Database = databaseName;
        BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
        SqlConnection sqlCon = new SqlConnection(publicConString);
        ServerConnection connection = new ServerConnection(sqlCon);
        Server sqlServer = new Server(connection);
        Database db = sqlServer.Databases[databaseName];
        sqlBackup.Initialize = true;
        sqlBackup.Checksum = true;
        sqlBackup.ContinueAfterError = true;
        sqlBackup.Devices.Add(deviceItem);
        sqlBackup.Incremental = false;
        sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
        //sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
        sqlBackup.FormatMedia = false;
        sqlBackup.SqlBackup(sqlServer);

备份文件夹问题

从您的描述中,我认为您想将数据库备份到网络共享文件夹,对吗?

根据错误提示,我认为SQL Server服务帐户对共享文件夹没有足够的权限。请确保SQL Server服务帐户是域帐户,并且具有足够的权限。

更多信息请参考此信息


如果您的帐户没有访问网络驱动器的足够权限,则无法将数据库备份到网络驱动器。