Enabling sp_execute_external_script to run R scripts in SQL Server 2016

SP_EXECUTE_EXTERNAL_SCRIPT is a stored procedure that execute provided script as argument on external script to a provided language (in this case R language). To enable normal function of this external stored procedure, you must have administrator access to your SQL Server instance in order to run sp_configure command (and set following configuration):

EXECUTE sp_configure;

To enable execution of external script add an argument:

EXECUTE sp_configure 'external scripts enabled', 1;

And after that run the reconfiguration as:


This is a standard procedure to do so, also described on BOL for running sp_execute_external_script.

But I have seen too many people struggling with this; after running this reconfigure on sp_configure they still get run value for external scripts enabled set to 0.

2016-07-26 09_45_44-

Which literally means that execution of R script will not work.

In this case go to services and restart service: SQL Server Launchpad (SQLSERVER).



And this will take affect that run_value will be set to 1.


Enjoy coding T-SQL and R.


Data science show at SQL Server Radio

SQL Server Radio with Matan Yungman (info | twitter| company ) and Guy Glantser (info | twitter | company ) was hosting me for SQL Server radio 52th series. Main topic was discussion onย  data science, statistics, who data scientist is and what SQL Server offers with R integration, SSRS, PowerBI, Excel and other tools.


45 minutes of talk and laughter with Matan and Guy. Both are very funny and highly professional and our discussion was full of interesting topics and questions, anecdotes and discussing use cases from experiences.

Listen to podcast of 52th show of SQL Server radio and hear what we were laughing and discussing about.

To recap what we were nibbling and chatting about (well, what I was chatting and I am still laughing hearing the show he he):

  • what data science is who data scientist is
  • Problems with outsourcing data scientists
  • What tools are commonly used in data science
  • What Microsoft is offering with SQL Server 2016
  • Purpose and goals of data science
  • Predictions, models and analytics
  • R language and R integration
  • Use cases from the field


Enjoy listening and thank you guys Matan and Guy for this show, I had a great time!

Working folders, logs and sessions for sp_execute_external_script

When running with R code and sp_execute_external_script it is very handy to know where all the output log files are being generated and what additional information about the session is available and which folders are useful when working with external stored procedure sp_execute_external_script.

Session information is stored on your local disk under location:

C:\Program Files\Microsoft SQL Server\MSSQL13.SQLSERVER\MSSQL\ExtensibilityData

with subfolders: \SQLSERVER01\2EDE2133-E0A1-42A9-8F1E-958E87AB92B5

2016-07-20 19_51_10-SQLSERVER2016RC301

These folders consist of subfolders and files of sessions ID. Nature of this folders is that they are purged after the session is closed – it can be from 6 to n-minutes. On my client I have by default 6 minutes. After this time, the sessions are closed and if you rerun the sp_execute_external_script from SSMS you will notify a slight delay because the R engine needs to re-establish all the sessions again in comparison of running the same script one time after another time.

The session file includes following RevoScaleR code:

sessionDirectory <- 'C:\\PROGRA~1\\MICROS~2\\MSSQL1~1.SQL\\MSSQL\\EXTENS~1\\SQLSERVER01\\C13E33C2-A71D-4ED3-AA13-B79BB2A1FBC1';
sessionId <- 'C13E33C2-A71D-4ED3-AA13-B79BB2A1FBC1';
scriptFile <- file.path(sessionDirectory, paste(sessionId, '.R', sep=''));
rxIgnoreCallResult <- .Call('RxSqlSessionStart', list(sessionDirectory=sessionDirectory, sessionId=sessionId, waitTime=-1));


Those who wanted to capture the output and log file that R engine usually generates. With sp_execute_external_script these files can not be navigated to, since procedure is a CLR and using preassigned assembly, even though the script is sent to R engine using CMD batch. This peace of information can be found on in file: C:\Program Files\Microsoft SQL Server\MSSQL13.SQLSERVER\MSSQL\Binn\rlauncher.config and for my configuration the content is as following:

RHOME=C:\Program Files\Microsoft SQL Server\MSSQL13.SQLSERVER\R_SERVICES
MPI_HOME=C:\Program Files\Microsoft MPI

These are all the global settings for R engine that is ran from SQL Server 2016 engine. And assembly to support R engine is located:

C:\Program Files\Microsoft SQL Server\MSSQL13.SQLSERVER\MSSQL\Binn\RLauncher.dll.

which is also the name of the service:

2016-07-20 20_39_01-Services


And finally, by running:

exec sp_helpextendedproc sp_execute_external_script

With this procedure one can find out that sp_execute_external_script is presented as dll.

2016-07-20 20_55_14-roles_security_sp_execute_external_Script.sql - SICN-00031_SQLSERVER2016RC3.mast

Happy T-SQLRing! ๐Ÿ™‚


*Blog post might change due to new/better information regarding this topic! This will be marked in accordance.

R Services and R Language forum section at SQLServerCentral.com

NEWS!!! R Services and R integration with SQL Server 2016 get its own forum section at SQLServerCentral site.

After e-mail discussion with Steve Jones (t|b) – editor of SQLServerCentral, we have agreed to add the R Services section to SQLServerCentral forum site for community to have a designated place on forum site, where bloggers, community members, programmers, statisticians, DBA, sysadmins, data scientists will be joined and share ideas, problems, riddles, code, questions and answers all on one place.

So welcome to this tiny new section in this large Forum; Address is following (or you can navigate through Forums -> Programming -> R Services and R Language): http://www.sqlservercentral.com/Forums/Forum3811-1.aspx

2016-07-17 19_02_11-R Services and R Language

And thank you Steve for helping with this!