向高手请教一个问题:
当我执行:
use master
exec xp_cmdshell 'osql /S musqlserver /U sa /P mypwd /d haodb /Q "select top 10 * from trandetail" /o C:/my1.xls'
以上执行成功,会产生新文件:C:/my1.xls'
然后我想将此文件直接copy到另一台电脑中[已建连接]
执行
EXEC xp_cmdshell 'copy C:/my1.xls //192.168.42.42/d$'
时候,系统会提示"拒绝访问"
而在DOS窗口中执行:
C:/my1.xls //192.168.42.42/d$ 则没有任何问题
我想应该是用户权限的问题
因为在sql中,用户是sa
在DOS中,用户则是administrator
那我应该怎么做??
先建立共享信用关系
master..xp_cmdshell 'net use //192.168.42.42/d$ 123 /user:domain/administrator'
关于net use的用法看帮助。
exec xp_cmdshell 'net use Z: //192.168.42.42/d$ /user:domain/administrator'
exec xp_cmdshell 'copy C:/my1.xls Z:/'
exec xp_cmdshell 'net use Z: /del'