日期:2014-05-18  浏览次数:20402 次

关于远程备份数据库的问题
有一服务器A和服务器B,想在A上备份数据库到B上去,但在建立远程映射exec master..xp_cmdshell 'net use w: \\servername\d$\test 密码 /user:servername\用户名' 的时候出现如下错误:

Cannot load the DLL Low-key to survive, or one of the DLLs it references. Reason: 126(The specified module could not be found.)
请有遇到类似问题的帮忙解决一下,B应该是没问题的,因为在另外一台服务器C上备份到B是可以的,但在A备份到B的时候就不行,不要说重装系统什么的,这样太麻烦了。



------解决方案--------------------
SQL code

--完整的过程
use master
go
IF OBJECT_ID('Backup_testdb')IS NOT NULL
DROP PROCEDURE Backup_testdb
GO
CREATE PROCEDURE [dbo].[Backup_testdb]
with encryption
AS
BEGIN

---显示高级选项(仅需执行一次)
EXEC sp_configure 'show advanced options', 1 

--GO 

RECONFIGURE 

--GO

---允许执行xp_cmdshell 
EXEC sp_configure 'xp_cmdshell', 1 

--GO 

RECONFIGURE 

--GO
 

---添加映射驱动器 
declare @string nvarchar(200) 

set @string = 'net use z:  \\192.168.3.3\test_Dbbak  "123" /user:SERVER\administrator' 

exec master..xp_cmdshell @string
 

---其中192.168.3.3为文件服务器的地址,DatabaseBackup为该服务器的共享文件夹,ERP-SERVER为机器名,administrator 6141 分别为共享时设置的用户名密码。 

----备份数据库至本地 
declare @date datetime 

set @date = GetDate() 

declare @str nvarchar(100) 

set @str = 'd:\test_Dbbak\Full_testdb_'+ convert(nvarchar(12), @date, 112)+right('00'+convert(nvarchar(2),DATEPART(HH,@date)),2) +'.bak' 

backup database testdb to disk=@str with compression
 

---With init为覆盖同名文件(本例设计为1天执行一次,不会出现覆盖的情况)。 

---拷贝到文件服务器 
declare @str1 nvarchar(100) 

set @str1 = 'copy '+ @str +' z:' 

exec master..xp_cmdshell @str1
 

---删除映射以及本地备份 
exec master..xp_cmdshell 'net use z: /delete' 

--declare @str2 nvarchar(100) 

--set @str2 = 'del '+@str+'' 

--exec master..xp_cmdshell @str2
 

---关闭允许执行cmdshell 

EXEC sp_configure 'xp_cmdshell', 0 

--GO 

RECONFIGURE 

--GO
 
----成功备份
END