1

I want to check that a file exists on a web server using the SQL Server.

I have tried the xp_cmdshell DIR. But it works only for local files.

Please let me know how to achieve this.

Thanks in advance.

Gaurav
  • 31
  • 7
  • SQL Server doesn't sound like the best tool for this job. Perhaps if you provide some background information we can help you find a workable solution. – David Rushton Dec 24 '15 at 09:38
  • There is an image file on the web server with extension either from .png, .jpg, or .gif. I have to check that the file has which extension & save its path in the database table. – Gaurav Dec 24 '15 at 09:49
  • Dir should work just fine with UNC paths, assuming the user account used for running SQL Server has access to the directory, but you probably should do this outside the database – James Z Dec 26 '15 at 18:38

2 Answers2

1

After searching for a few days, I found the following which works well :-

When you have to put file, like BCP result, or a backup in a remote drive, just map this drive into windows don't work, it must be mapped on SQL Server to!, to do this, try like this:

exec xp_cmdshell 'net use p:\ \Server\Folder\Folder\Folder\ /Domain\Login /Password'

Reference : https://social.msdn.microsoft.com/Forums/en-US/6eca2d62-eb86-4f23-9b86-6f917017f50c/bcp-utility-via-xpcmdshell-and-network-drive?forum=sqlsecurity

Gaurav
  • 31
  • 7
0

You can not access with any user, means while access directory in sqlserver you have to only use that user which have directory rights and your sqlserver services running in that user.

if you access in normal user or say simply Network Service or 'Local Service' user (in which sqlserver service run default) you can access all resources of your computer via network too (ie. \yourname\sharablefolder ), but not access sharable folder in the network.

either backup resore : http://www.sqlservercentral.com/Forums/Topic631787-146-1.aspx

or execute command :

http://www.sqlservercentral.com/Forums/Topic808580-359-1.aspx

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

https://www.simple-talk.com/community/forums/thread/72262.aspx

https://social.msdn.microsoft.com/forums/sqlserver/en-US/c5ce5e21-17e7-4763-ba68-d3bb7dad213f/access-denied-on-xpcmdshell-with-certain-folders

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58