SQLTeam.com | Weblogs | Forums

.bat doesn,t work in sp


#1

Hi All,

I'm new in shell have problem run .bat in store proc ,.bat working manually ,but in sp no

my sp:

DECLARE @CMDSQL VARCHAR(1000)

SET @CMDSQL = '\vsrv-ad01\Public\IT\Evgeny\CopyReports.bat'
EXEC master..xp_cmdshell @CMDSQL

what wrong?

Thanks for help


#2

Who/what user is making the proc call?
Does it have permissions to \vsrv-ad01\Public\IT\Evgeny\ folder?


#3

I would like after that schedule that sp, so sqlAgent

after running the sp I have message

NULL
C:\Windows\system32>XCOPY
Invalid path
0 File(s) copied
NULL


#4

how are you running the sp?


#5

for now manualy


#6

and when you will deploy it as a sql job, which user will be running the sql job?


#7

sqlagent


#8

Shoud be:

DECLARE @CMDSQL VARCHAR(1000)

SET @CMDSQL = '\\vsrv-ad01\Public\IT\Evgeny\CopyReports.bat'
EXEC master..xp_cmdshell @CMDSQL

#9

Jotorre, I think that was due to the forum, it strips out double back slash


#10

Sorry ,but I received same result

NULL
C:\Windows\system32>XCOPY /s /e /d /y "\vsrv-ad01\Public\IT\Evgeny\Canada\11A - SUKH HEER -IRIS" "
Invalid path
0 File(s) copied
NULL


#11

your issue has nothing to do with sql server but with xcopy.


#12

so,what 's wrong ,when I manualy run batch file its work correctly


#13

Does the account sql server is running under have permissions on the path?


#14

Its my file could you please take a look and let me know what's issue?

XCOPY /s /e "xxxxx" "xxx\OneDrive - xxxx"


#15

If not grant impersonate on a windows account having permissions on the share and use execute as.


#16

yes,have the permission