none
run an r script on a remote server from MS SQL when executing a stored procedure RRS feed

  • Question

  • I need to run an r script on a remote server from MS SQL when executing a stored procedure. xp_cmdshell does not allow this: EXEC xp_cmdshell 'start \\192.168.xxx.xxx.bin\Rscript.exe \\192.168. xxx.xxx.\bin\test_3. R'. Communication with the remote server is established because the simple system commands EXEC xp_cmdshell 'dir\\192.168.xxx.xxx.bin' are executed . It also fails to execute the remote R script also from the command line of the SQL server host cmd: start \\192.168.xxx.xxx.bin\Rscript.exe \\192.168. xxx. xxx.\bin\test_3. R
    Thursday, September 17, 2020 4:32 PM

All replies

  • What version of SQL Server are we talking about? 

    If you are on 2016, (or later), you have the ability to execute R, (and Python), scripts from inside SQL Server, by using sp_execute_external_script.

    I have written quite a few blog posts about this. SQL Server 2016 R Services is a good starting point.

    Let us know how it goes.


    http://www.nielsberglund.com | @nielsberglund

    Friday, September 18, 2020 4:15 AM
  • Communication with the remote server is established because the simple system commands EXEC xp_cmdshell 'dir\\192.168.xxx.xxx.bin' are executed .

    You are launching cmd.exe on the server where SQL is running and you doing a directory list on a network share..

    I need to run an r script on a remote server 

    Your example is not running the script ON the remote 192.168.xxx.xxx server. You are copying the Rscript.exe file from the remote system (via network share \\servername\sharename\filename) to the server that is running SQL and executing it on that machine.

    See my other reply about using psexec.

    Friday, September 18, 2020 3:51 PM