Troubles connecting remote database sql via R script with Machine learning 2019

2

I have installed SQL Machine Learning 2019 and I have enabled R and Python. I tested the installation and it works fine.

So when I try to connect to remote database SQL I had a lot of errors.

Here my code:

EXECUTE sp_execute_external_script 

@language = N'R'
, @script = N'

 library(odbc)
 con = dbConnect(odbc(), Driver = "ODBC Driver 17 for SQL Server", Server = "remote_server", Database = "test", UID="tuser", PWD="tpassword")'
, @input_data_1 = N''
, @output_data_1_name = N'

Errors:

Msg 39004, Level 16, State 20, Line 0 A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 2, Line 0 An external script error occurred:

Error: nanodbc/nanodbc.cpp:950: 08001: [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [65].
Error in execution. Check the output for more information. Error in eval(ei, envir) : Error in execution. Check the output for more information. Calls: runScriptFile -> source -> withVisible -> eval -> eval -> .Call

Execution halted

other test:

EXECUTE sp_execute_external_script 

@language = N'R'
, @script = N'
 library(DBI)
 con = dbConnect(drv = odbc::odbc(), Driver = "ODBC Driver 17 for SQL Server",  Database = "test", Server = "remoteserver", UID="tuser", PWD="tpassword")
, @input_data_1 = N''
, @output_data_1_name = N'

Errors:

Msg 39004, Level 16, State 20, Line 0 A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 2, Line 0 An external script error occurred:

Error: nanodbc/nanodbc.cpp:950: 08001: [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [65].
Error in execution. Check the output for more information. Error in eval(ei, envir) : Error in execution. Check the output for more information. Calls: runScriptFile -> source -> withVisible -> eval -> eval -> .Call

Execution halted

And Last Test:

EXECUTE sp_execute_external_script 

@language = N'R'
, @script = N'
 library(RODBC)
 con=odbcDriverConnect(''driver={ODBC Driver 17 for SQL Server}; server=remoteserver;database=remotedb;uid=tuser;pwd=tpassword'')
, @input_data_1 = N''
, @output_data_1_name = N'

An the errors are:

STDERR message(s) from external script: Warning messages: 1: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server}; server=remoteserver;database=remotedb;uid=tuser;pwd=tpassword") : [RODBC] ERROR: state 08001, code 65, message [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [65]. 2: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server}; server=remoteserver;database=remotedb;uid=tuser;pwd=tpassword") : [RODBC] ERROR: state HYT00, code 0, message [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired 3: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server}; server=remoteserver;database=remotedb;uid=tuser;pwd=tpassword") :

STDERR message(s) from external script: [RODBC] ERROR: state 08001, code 65, message [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. 4: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server}; server=remoteserver;database=remotedb;uid=tuser;pwd=tpassword") : ODBC connection failed

It seems That I have a network problems with another server, but I checked network connections, firewall permissions, and also I checked Name Pipes protocol and it is enabled and every checks are OK and connection test are working fine.

Could someone help me? Or give some ideas to solve this issue?

r
sql-server
asked on Stack Overflow Sep 3, 2020 by Carlos A. Alfonso • edited Sep 4, 2020 by desertnaut

1 Answer

0

Named pipes is mostly used for connecting to the same machine (where the client runs). Specify a TCP connection to the server:

Server = "tcp:servername"

Also, check the windows firewall rules which could block any outgoing connections from the APP containers of SQLServer.

answered on Stack Overflow Sep 4, 2020 by lptr • edited Sep 4, 2020 by lptr

User contributions licensed under CC BY-SA 3.0