SQL Server Connecting to SQL through R in Azure Machine Learning Studio

vmpqdwk3  于 2023-05-05  发布在  Mac
关注(0)|答案(1)|浏览(173)

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!

iezvtpos

iezvtpos1#

I tried to connect my sql database in ML studio using below R script:

con <- odbc::dbConnect(odbc::odbc(),
                       DRIVER="ODBC Driver 17 for SQL Server",
                       SERVER="<serverName>",
                       DATABASE="<databaseName>",
                       UID="<userName>",
                       PWD="<password>",
                       port = 1433 )

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.

相关问题