备份文件夹问题

时间:2011-12-23 14:24:15

标签: c# sql-server-2005 smo

运行下面的代码时,我不断收到“访问被拒绝”,但我对该文件夹拥有完全的管理权限。

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

文件夹目标是@“\ networkDrive \ backups”;

我也试过@“C:\ backups”\和@“C:\ backups”

    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);

1 个答案:

答案 0 :(得分:3)

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

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

有关详细信息,请参阅此info


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