以下这段代码,用查询分析器运行是正常的可以运行。
然后用作业来调度它一小时执行一次就出问题了,虽然没有提示错误消息,也显示为成功运行,但是没有正常执行拷贝的动作,也就是e:\bakcup没有看到要拷贝的文件。
最奇怪的是,查看作业历史记录里面的运行时间有两种,只执行一秒的都没有正常拷贝,执行时间为20秒的就有正常拷贝,也就是说,有的时候正常拷贝,有的时候没有正常拷贝,这实在太奇怪,希望有人能试试这段代码,看看问题怎么回事?谢谢!
exec master..xp_cmdshell 'del d:\*.bak'
exec master..xp_cmdshell 'net use e: \\192.0.0.11\d "123456" /user:192.0.0.11\administrator'
declare @bkfile nvarchar(1000)
set @bkfile='d:\'+substring(convert(char(10),getdate(),112),5,4)+'_'+stuff(convert(char(5),getdate(),108),3,1,'')+'.bak'
backup database airport to disk=@bkfile with init
exec master..xp_cmdshell 'copy d:\*.bak e:\backup'
exec master..xp_cmdshell 'net use e: /delete'
然后用作业来调度它一小时执行一次就出问题了,虽然没有提示错误消息,也显示为成功运行,但是没有正常执行拷贝的动作,也就是e:\bakcup没有看到要拷贝的文件。
最奇怪的是,查看作业历史记录里面的运行时间有两种,只执行一秒的都没有正常拷贝,执行时间为20秒的就有正常拷贝,也就是说,有的时候正常拷贝,有的时候没有正常拷贝,这实在太奇怪,希望有人能试试这段代码,看看问题怎么回事?谢谢!
exec master..xp_cmdshell 'del d:\*.bak'
exec master..xp_cmdshell 'net use e: \\192.0.0.11\d "123456" /user:192.0.0.11\administrator'
declare @bkfile nvarchar(1000)
set @bkfile='d:\'+substring(convert(char(10),getdate(),112),5,4)+'_'+stuff(convert(char(5),getdate(),108),3,1,'')+'.bak'
backup database airport to disk=@bkfile with init
exec master..xp_cmdshell 'copy d:\*.bak e:\backup'
exec master..xp_cmdshell 'net use e: /delete'
把作业所有者改为administrator后也是一样的,刚刚连续试了3次,两次1秒,一次20秒。
这样你就可以查看错误了。
exec master..xp_cmdshell 'net use e: \\192.0.0.11\d "123456" /user:192.0.0.11\administrator >>com.log'
declare @bkfile nvarchar(1000)
set @bkfile='d:\'+substring(convert(char(10),getdate(),112),5,4)+'_'+stuff(convert(char(5),getdate(),108),3,1,'')+'.bak'
backup database airport to disk=@bkfile with init
exec master..xp_cmdshell 'copy d:\*.bak e:\backup >>com.log'
exec master..xp_cmdshell 'net use e: /delete >>com.log'
然后你去看com.log文件就清楚了。
这个com.log是不是在 windows\system32里面,我打开是空的文件。现在在新的机器上装一个SQL Server,单独对这个作业试试。
现在在新的机器上装一个SQL Server,单独对这个作业试试。等待结果
楼主可以看看两台机器的设置哪个地方不同