SQL Server 2019 External Scripts Network Drive Access Denied

Nikolaus Haminger 11 Reputation points

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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,871 questions
{count} votes

4 answers

Sort by: Most helpful
  1. CathyJi-MSFT 21,096 Reputation points Microsoft Vendor

    Hi @Nikolaus Haminger ,

    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.

    0 comments No comments

  2. Nikolaus Haminger 11 Reputation points

    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?

  3. Erland Sommarskog 102.2K Reputation points

    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.

    0 comments No comments

  4. Nikolaus Haminger 11 Reputation points

    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.