我有一个存储过程,它为特定数据库执行数据库备份,如下所示:
ALTER PROC [dbo].[SP_Backup]
@DataBaseName NVARCHAR(500) = NULL
@fullPath NVARCHAR(500) OUTPUT
AS
BEGIN
DECLARE @dbpath NVARCHAR(500);
SELECT @DataBaseName = DB_NAME()
SELECT @dbpath = physical_name
FROM sys.database_files
WHERE ( name = N'myDb' );
SELECT @fullPath = SUBSTRING(@dbpath, 0,
LEN(@dbpath) - CHARINDEX('\',
REVERSE(@dbpath)
+ '\') + 1);
SELECT @fullPath = @fullPath + N'\Backups\' + @DataBaseName + N'.bak'
BACKUP DATABASE @DataBaseName
TO DISK = @fullPath;
END;
问题是,它可以在一台服务器上运行,而不能在另一台服务器上运行(服务器在同一台机器上。--sql 2008 r2)。我得到异常“备份数据库异常终止。”
备份文件夹具有相同的权限设置,如下所示:
C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server1\MSSQL\DATA\Backup
C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server2\MSSQL\DATA\Backup
和 sql 用户也是一样的;
在日志文件中有以下信息:
Error: 18204, Severity: 16, State: 1.
BackupDiskFile::CreateMedia: Backup device 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server2\MSSQL\DATA\Backups\myDb.bak' failed to create. Operating system error 3(failed to retrieve text for this error. Reason: 1815).
Error: 3041, Severity: 16, State: 1.
BACKUP failed to complete the command BACKUP DATABASE myDb. Check the backup application log for detailed messages.
这可能是什么原因?