Harry
Harry

Reputation: 451

Set the path when checking if a file exists in a folder via SQL Server 2016

I am using the following code 1 to check if a file exists in a folder and it works. Then when I move the file to another folder, saying adding multiple New folder, it does not work, only 0 is returned, not 1.(I am sure the path is correct and the file does exist)

I cannot figure out what is the problem.

Code 1:

 DECLARE @result INT
 EXEC master.dbo.xp_fileexist 'C:\Users\$11F7BC3A.jpg', @result OUTPUT
 select @result as 'results'

Code 2:

 DECLARE @result INT
 EXEC master.dbo.xp_fileexist 'C:\Users\James.James\New folder\New folder\$11F7BC3A.jpg', @result OUTPUT
 select @result as 'results'

Upvotes: 0

Views: 182

Answers (1)

Gen Wan
Gen Wan

Reputation: 2009

Please create two new folders under Users & put in the file & use the below code to test it:

 DECLARE @result INT
 EXEC master.dbo.xp_fileexist 'C:\Users\New folder\New folder\$11F7BC3A.jpg', @result OUTPUT
 select @result as 'results'

If this does work, it means you do not have the full permission to manage James.James folder

Update:

Please follow the instruction in the link to configure the permission:

https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-file-system-permissions-for-database-engine-access?view=sql-server-ver15

Upvotes: 1

Related Questions