February 12, 2024 at 3:49 pm
DECLARE @var VARCHAR(2000)
SET @var = 'dir ' + '\\company.sharepoint.com@SSL\DavWWWRoot\sites\OrderSite\OrderDocs\ORD001\*Invoice*33023*.pdf' + ' /b'
EXEC master..xp_cmdshell @var
Following error occurs : Access Denied. Before opening files in this location, you must first add the web site to your trusted sites list, browse to the web site, and select the option to login automatically.
I am able to browse the directory from the dos command without any problem.
When i used EXEC master..xp_cmdshell 'whoami'. I get the result domain\Username, it is the same user i can use to browse the directory. I dont know why it is not working from xp_cmdshell SQL command
February 12, 2024 at 10:09 pm
xp_cmdshell runs server side so you would need to be able to browse the directory from the server side not your local dos command line.
My opinion though - SQL Server and xp_cmdshell is an odd tool to use for downloading files from sharepoint... Powershell is a much better way to do it in my opinion...
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
February 18, 2024 at 6:49 pm
it's permissions.
you have permissions, but the account running the SQL service does not.
regardless of who is running the SQL command executing xp_cmdshell, once outside of SQL server, xp_cmdshell runs as the service account that runs SQL Server...so if that is NT AUTHORITY\NETWORKSERVICE for example, it ends up passing the computername as the AD account to try and access the unc path. if you are actually using an AD account to run the service, perfect! just add that account to the share under security.
you can fix that local account issue by adding a proxy account as your own account TEMPORARILY as the proof of concept.
find or create a new domain account that has access only to that share and add that as the proxy account.
Lowell
February 20, 2024 at 3:16 am
My opinion though - SQL Server and xp_cmdshell is an odd tool to use for downloading files from sharepoint... Powershell is a much better way to do it in my opinion...
"It Depends". Doing the xp_CmdShell thing (to execute a DOS or PoSh command) is very useful when it comes to building "womb-to-tomb" jobs instead of have to jump back and forth.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply