how can i access a file/folder over network through XP_CMDSHELL in sql server 2008?

Yaqub Ahmad picture Yaqub Ahmad · Nov 2, 2011 · Viewed 11.8k times · Source

I am trying to access a folder/directory using 'EXEC MASTER..XP_CMDSHELL' it works for the local file/folder, how ever it can not access the folder over network.

EXEC MASTER..XP_CMDSHELL 'c:\Images'  --Works fine
EXEC MASTER..XP_CMDSHELL '\\IPaddress\Images' -- returns "Access is denied."

Please note that i can access the network location but not using sql server.

Sql server is running under Winodws Authentication mode. Sql server is using 'nt authority\network service' account to access the remote Folder.

Regards

Answer

K. Bob picture K. Bob · Nov 2, 2011

If you run xp_cmdshell 'whoami.exe' it will tell you the account the command is running under. If this account doesn't have permissions on the network, you'll get the error you are seeing.

Check the SQL documentation for changing this account/permissions.