Julius S.
Julius S.

Reputation: 704

Execute R script with sp_execute_external_script in MSSQL

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:

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.

Upvotes: 0

Views: 706

Answers (1)

lptr
lptr

Reputation: 6788

For reading/writing from/to folders with sp_execute_external_script, assign permissions to "ALL APPLICATION PACKAGES"

For accessing other machines/external resources, check (and disable) the blocking outgoing firewall rules for the several "AppContainers-nn in SQLServer".

Upvotes: 2

Related Questions