So you’ve got an instance of SQL 2016 running and you want to play with running R code inside SQL stored procedures. You’ve enabled external scripts and given permissions to some users to execute those scripts. You open Management Studio and execute sp_execute_external_script with some simple R code.
Do you know what account that code is running under?
Image may be NSFW.
Clik here to view.
You’re not running as yourself, even though that’s the account you signed into SSMS as.
You’re not running under the server account that SQL or SQL Launchpad run under.
You’re running as a new account created when you installed SQL R Service In Database for the purpose of running R code.
Image may be NSFW.
Clik here to view.On the server SQL creates a new Windows group, SQLRUserGroup and 20 new Windows accounts, MSSQLServer01 through 20. If you’re running a named instance the names will be SQLRUserGroup<instance> and <instance>01 through 20, respectively. If you need more than 20 accounts you can add more on the Advanced tab for the properties of the SQL Launchpad service. You can also specify if you need the passwords changed based on a password policy. The passwords themselves are generated by keys inside the RegisterRext.exe.config file. If you connect to R Server from a client you’ll also need to grant database access to the Windows group, it doesn’t have and database rights by default.
There’s a few ways to see which account is running. You can query the R environment, like in the following example.
Image may be NSFW.
Clik here to view.
You can also use the built in dynamic management views. Sys.dm_external_script_requests will show the accounts that any currently running R code are using.
Image may be NSFW.
Clik here to view.
This solves the issue in my post last week, about not being able to access a file stored on a network share using R code inside a SQL 2016 stored procedure. In my case I just had to extend the read permissions on the share. But it’s good to know when you run any external scripts.
References
Modify the User Account Pool for SQL Server R Services – MSDN
https://msdn.microsoft.com/en-us/library/mt591988.aspx
Monitoring Reports for R on SQL Server 2016 – Ginger Grant
http://www.desertislesql.com/wordpress1/?p=1549
Permissions question in R and SQL 2016
https://www.reddit.com/r/SQLServer/comments/54lfz7/permissions_question_in_r_sql_server_2016/