when check directory at shared path remotely it display not exist (false) although it exists

ahmed salah 3,216 Reputation points
2022-08-05T22:47:23.297+00:00

I have shared path remotely '\192.168.7.9\Import\8' I face

issue when try to check this directory path exist or not .

when run script python on sql server 2019 it must

return true because directory path exist but my

issue is python script return false although directory exist .

script python

declare @ExportPath varchar(max)='\\192.168.7.9\Import\8'  
EXEC sp_execute_external_script  
@language =N'Python',  
@script=N'  
import os  
d = os.path.isdir(ExportFilePath)  
print(d)'  
,@params = N'@ExportFilePath NVARCHAR(MAX)'  
,@ExportFilePath = @ExportPath  

this script python working good on local shared path
but on remotely shared path as my case it return flase as not exist directory although directory exist and have full permission
Expected result is True

228588-image.png

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,675 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 100.9K Reputation points MVP
    2022-08-06T07:57:28.563+00:00

    The Python script runs under the Launchpad service which by default has very limited permissions. Furthermore, this is a local machine account, so it is not known on the other machine. You could grant permission to the machine account (i.e. DOMAIN\MACHINE$) for the computer where SQL Server runs on the file share, but I am not sure this is the best of ideas.

    The main intention of the Python support is to perform computing for machine learning. It is not really intended for data import/export. You should probably look into a different solution altogether, like SSIS.

    0 comments No comments

  2. YufeiShao-msft 7,056 Reputation points
    2022-08-08T08:32:54.5+00:00

    Hi @ahmed salah ,

    By default, external Python scripts only have read access permission to their working directories, you can first check if you have enough permissions.

    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.

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

    https://learn.microsoft.com/en-us/sql/machine-learning/install/sql-server-machine-learning-services-2019?view=sql-server-ver15#file-permissions

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.