以下这段代码,用查询分析器运行是正常的可以运行。
然后用作业来调度它一小时执行一次就出问题了,虽然没有提示错误消息,也显示为成功运行,但是没有正常执行拷贝的动作,也就是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' 

解决方案 »

  1.   

    mei you cuo wu ti shi, you dian qi guai
      

  2.   

    楼主参考一下这个,个人认为是作业的问题。http://blog.csdn.net/sdhdy/archive/2009/05/14/4183401.aspx看看你的作业的所有者是SA还是ADMINISTRATOR。
      

  3.   


    把作业所有者改为administrator后也是一样的,刚刚连续试了3次,两次1秒,一次20秒。
      

  4.   

    呵呵,不是没有错误提示,是你的程序没有检测错误,你可以在命令后面跟 ' >copy.log'
    这样你就可以查看错误了。
      

  5.   

    exec master..xp_cmdshell 'del d:\*.bak  >>com.log' 
    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文件就清楚了。
      

  6.   


    这个com.log是不是在 windows\system32里面,我打开是空的文件。现在在新的机器上装一个SQL Server,单独对这个作业试试。
      

  7.   


    现在在新的机器上装一个SQL Server,单独对这个作业试试。等待结果
      

  8.   

    这就可能是服务器的设置问题,或者SQL负荷,反复操作数据库造成的
    楼主可以看看两台机器的设置哪个地方不同