question

NikolausHaminger-3297 avatar image
0 Votes"
NikolausHaminger-3297 asked NikolausHaminger-3297 commented

SQL Server 2019 External Scripts Network Drive Access Denied

Hello Community,

so we are invoking a Python script by using the sp_execute_external_script command. Within this Python script, we access files that are located on a network drive (r/w). This works well if the files are located on a local drive and full access for 'ALL APPLICATION PACKAGES' is permitted, but it doesn't work with files located on the network drive.

Does anybody know a way or workaround to access files on a network drive from an external script (Python or R)?

sql-server-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered

Hi @NikolausHaminger-3297,

By default, external Python and R scripts only have read access permission to their working directories.

If your Python or R scripts need access to any other directory, you need give either Read & execute and/or Write permissions to the NT Service\MSSQLLaunchpad service user account and ALL APPLICATION PACKAGES on this directory.

Follow the steps below to grant access.

1.In File Explorer, right click on the folder you want to use as working directory, and select Properties.
2.Select Security and click Edit... to change permissions.
3.Click Add...
4.Make sure the From this location is the local computer name.
5.Enter ALL APPLICATION PACKAGES in Enter the object names to select and click Check Names. Click OK.
6.Select Read & execute under the Allow column.
7.Select Write under the Allow column, if you want to grant write permissions.
8.Click OK and OK.

Refer to this MS document.


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NikolausHaminger-3297 avatar image
0 Votes"
NikolausHaminger-3297 answered NikolausHaminger-3297 edited

Hi @Cathyji-msft ,

thank you for your fast answer.

The method you suggested works well with files/directories on a local drive. However, it does not work with files/directories located on a network drive, even if the network drive is mapped to a drive letter.

Any other suggestions on how to access files/directories on a network drive?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NikolausHaminger-3297,

You have also give the permissions to the NT Service\MSSQLLaunchpad service user account and ALL APPLICATION PACKAGES on shared folders? Please check this, thanks.

0 Votes 0 ·

Yes, I have given permissions for both accounts. It still doesn't work. I have even changed the user of the Launchpad Service to a domain administrator -> it still doesn't work.

0 Votes 0 ·
ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered

Since the Launchpad Service runs under account that is local to the machine, it cannot be granted access to network drives. You could grant permission to the machine account, that is DOMAIN\MACHINE$, but you should consider the security implications of that. (And I am not sure that it would work given how locked down the Launchpad service is.)

Another alternative is to change the service account for the launchpad to a domain account, but I would not recommend that.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NikolausHaminger-3297 avatar image
0 Votes"
NikolausHaminger-3297 answered NikolausHaminger-3297 commented

Thank you for your answer.

I have tried both the solutions you suggested and it still doesn't work. I cannot access files on a network drive from a Python script. This is frustrating.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NikolausHaminger-3297,

What the error message that you got? Access denied?

0 Votes 0 ·

Hi @Cathyji-msft ,

sorry for the late answer. The error message is
PermissionError: [Errno 13] Permission denied: '\\Path\to\file'
(from the Python interpreter).

no matter what I tried, files and folders cannot be accessed if they are located on a network drive. I did a little bit of research and found out that those scripts are running in app containers, which don't have direct access to the file system. I am still curious why files on a local drive can be accessed and files on a network drive can't.

0 Votes 0 ·