我的目的是:
sql程序备份数据库完成后,将bak文件复制到本地电脑。复制文件时,我的电脑和服务器在loacl网络。
这是我的程序(bak DB 已完成):
create procedure CopyFile
as
begin
declare @DynamicSQL varchar(1000)
set @DynamicSQL='net use \\Dolphin-PC\ipc$ 123 /user:Administrator&&xcopy E:\"Database backup"\%Date:~0,4%%Date:~5,2%%Date:~8,2%\*.bak \\Dolphin-PC\D$\邮电\LocalDB\%Date:~0,4%%Date:~5,2%%Date:~8,2%\ /E /Y /H /K&&net use \\Dolphin-PC\ipc$ /delete'
--Configure extension procedure the cmd_shell enable
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;
exec xp_cmdshell @DynamicSQL
--Configure extended procedure cmd_shell disable
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',0;
reconfigure;
end
当我运行 proc 时,它提示:
occour system error 1312。
NULL
the session have not been complete.Maybe have been finished.
NULL
NULL
我在运行DOS
没有问题。DOS
命令是:
net use \\Dolphin-PC\ipc$ 123 /user:Administrator
xcopy E:\"Database backup"\%Date:~0,4%%Date:~5,2%%Date:~8,2%\*.bak \\Dolphin-PC\D$\邮电\LocalDB\%Date:~0,4%%Date:~5,2%%Date:~8,2%\ /E /Y /H /K
net use \\Dolphin-PC\ipc$ /delete
以另一种方式使用 sql 执行批处理:
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;
exec xp_cmdshell 'E:\"Database backup"\bakcpy.bat'
--Configure extended procedure cmd_shell disable
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',0;
reconfigure;
错误是:
NULL
C:\Windows\system32>net use \\Dolphin-PC\ipc$ 123 /user:Administrator
occur system error 1312.
NULL
The login session does not exits.Maybe finished.
NULL
NULL
C:\Windows\system32>xcopy E:\"Database backup"\20131115\*.bak \\Dolphin-PC\D$\js\LocalDB\20131115\ /E /Y /H /K
invalid disk format
0 file have been copied
NULL
C:\Windows\system32>net use \\Dolphin-PC\ipc$ /delete
Can't find network connection.
NULL
input NET HELPMSG 2250 to get more help
NULL
NULL