I am trying to execute an external R file with sp_execute_external_script in MSSQL:
EXECUTE sp_execute_external_script @language = N'R'
, @script = N'
source("C:/Rscripts/script.R");';
I get the following error (translated):
External script error:
Error in file(filename, "r", encoding = encoding) :
could not open connection
Calling: source -> withVisible -> eval -> eval -> source -> file
Additional warning:
In file(filename, "r", encoding = encoding) :
Could not open file 'C:/Rscripts/script.R': Permission denied
Which can be summed up as a file permission error.
I tried the following:
- assigning several server roles to the user which executes the sql script
- assigning full access rights to the folder and script file to user 'MSSQLLaunchpad' and group 'SQLRUserGroup'
but without success.
The *.R file contains valid R script and can be executed by using the script from the SQL query in RStudio.
We need to open an external R file as the procedure sp_execute_external_script only takes a varchar(max) @script argument.
source("C:\Rscripts\script.R");