Friday, October 14, 2016

How to run R script under SQL Server 2016

SQL Server 2016 has one new feature: R services. This is a good news for data scientist. You can choose install SQL Server 2016 express version with advanced service, or you can also choose to upgrade your current SQL Server older express version to 2016 express to use the new feature. Note after you finished your installation, you need to manually install the feature using SQL Server 2016 installation program.

After you finished the installation, you need to lauch SQL Server Management Service 2016, and run the following script:
Exec sp_configure  'external scripts enabled', 1  
Reconfigure  with  override  
After running this script, you need to restart your SQL Server Database instance, and run the following script:
Exec sp_configure  'external scripts enabled'  
After running the above script, it should get the following result:
 
After finish above configuration, you need to manually restart SQL Server LauchPad service:
To restart the LauchPad service, please go to Windows Administrative Tools -> Services and find "SQL Server LauchPad (Your DB Name)"


Now the last step to test if you can run R script:
exec sp_execute_external_script  @language =N'R',  
@script=N'OutputDataSet<-InputDataSet',    
@input_data_1 =N'select 1 as hello'  
with result sets (([hello] int not null));  
go  
Expected Results:

hello 1

If experience the following error, you need to restart the LauchPad service.

Msg 39011, Level 16, State 1, Line 1
SQL Server was unable to communicate with the LaunchPad service. Please verify the configuration of the service.


Reference:
https://msdn.microsoft.com/en-us/library/mt696069.aspx
http://dba.stackexchange.com/questions/120205/msg-39011-sql-server-was-unable-to-communicate-with-the-launchpad-service