I am trying to connect to our SQL database how we usually connect to our DB in R. Locally we use the following script, both with and without the port number (since I only need 1433 which is default):
con <- odbc::dbConnect(odbc::odbc(),
DRIVER="ODBC Driver 17 for SQL Server",
SERVER="Server,port",
DATABASE="Database",
UID="User",
PWD="Password")
Unfortunately, this is giving me the following error.
Error: nanodbc/nanodbc.cpp:1118: 00000: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection Traceback:
I opened up an environment in Python and used pyodbc
conn = pyodbc.connect(
r'DRIVER={ODBC Driver 17 for SQL Server};'
r'SERVER=Server;'
r'DATABASE=Database;'
r'UID=User;'
r'PWD=Password;'
r'PORT=1433;'
)
And I was able to connect and run a query with no problem. Any advice on this? The drivers are present in the compute instance, so not sure why I'm unable to connect.
When I ran an R script through the terminal I got this error.
sudo Rscript connectSQLserver.R Error: nanodbc/nanodbc.cpp:1118: 00000: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection Execution halted
Any help would be appreciated!
1条答案
按热度按时间iezvtpos1#
I tried to connect my sql database in ML studio using below R script:
It connected successfully without any error:
Make sure allow remote connections to the sql server
Error: nanodbc/nanodbc.cpp:1118: 00000: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection Traceback
Above error may be cause of Invalid connection string or network issue. Once check the connection string and check network connectivity, check sql server configuration, check firewall settings.