0

I want to get files information on share folder using this command :

EXEC master..xp_cmdshell 'dir \\Server\d$\folder1\folder2'

but I get an error

Access is denied

When I tried using cmd it works with dir command.

Is there any permission or anything I can do? Thanks for the help

  • If you are using SQL 2017 or later, see if the view sys.dm_os_enumerate_filesystem can provide you the directory information you are looking for – Sparky Aug 14 '20 at 04:24
  • 3
    An SQL server is running usually as service with bulti-in local system account. The local system account has usually access to all files on local hard disk, but no permissions to access any files and folders on other machines. Your user account has obviously the permissions to access the folder on other server. So this is a classic account permission issue caused by thinking what you can access with your account can be accessed also by all programs running on the same machine even on using a different account. – Mofi Aug 14 '20 at 05:08
  • 3
    There are multiple methods to solve this access permission issue all written already thousands of times on hundreds of web pages. You can explicitly share the folder on the other machine and grant read (and if needed also write) access to everyone. Or you use a batch file using command `net use` to map a network drive for this folder on other machine using your credentials (user name and password), makes the file accesses and disconnects the network drive. See also [What must be taken into account on executing a batch file as scheduled task?](https://stackoverflow.com/a/41821620/3074564) – Mofi Aug 14 '20 at 05:12
  • I figured out it because the service account was nt service/. in my case i cant restart the sql service to change log on as local system. is there a way that i can get access to local system with nt service? (sorry for my bad English) Thank you. – Reinardus Hans Aug 18 '20 at 06:16

0 Answers0