I am not able to access the SQL Server database hosted on Azure Windows VM from the RStudio Connect server. The SQL Server is configured to allow remote connections. I tried the following R code in vain. I also reviewed other posts on this forum. But, none of them addressed this specific situation.
odbc.ini file content:
[dbname]
Driver = /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
Server = azure_wvm_name.corp.mycompany.com
ServerSPN = MSSQLSvc/azure_wvm_name.corp.mycompany.com:1433
Database = sqldb
Port = 1433
UID = mycompany\rkahn
PWD = myPassword
Trusted_Connection = yes
Encrypt = yes
TrustServerCertificate = yes
Kerberos = Yes
telnet ip_address 1433
, as suggested by 'AlwaysLearning' works.
Can someone let me know what am I missing in my code?
library(odbc)
library(DBI)
UserId <- 'mycompany\rkahn'
UserPassword <- 'myPassword'
dbname <- 'sqldb'
sqlsrvcon <- dbConnect(odbc(),
Driver = "ODBC Driver 18 for SQL Server",
Server = "azure_wvm_name.corp.mycompany.com",
Database = dbname,
UID = UserId,
PWD = UserPassword,
Port = 1433)
I get this error message: Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired [Microsoft][ODBC Driver 18 for SQL Server]MAX_PROVS: Connection string is not valid [87]. [Microsoft][ODBC Driver 18 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server.
I am able to connect to SQL Server through ODBC DSN
ubuntu@ip-xxx-xx-xx-xx:~$ isql -v dsnName
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
But when I try connecting using R
con <- DBI::dbConnect(odbc::odbc(), "dsnName")
I get this error: Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:self signed certificate] [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection
At last this worked for me:
library(odbc)
library(DBI)
UserId <- 'mycompany\rkahn'
UserPassword <- 'myPassword'
dbname <- 'sqldb'
sqlsrvcon <- dbConnect(odbc(),
Driver = "/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1",
Server = "azure_wvm_name.corp.mycompany.com",
Database = dbname,
UID = UserId,
PWD = UserPassword,
Encrypt="yes",
TrustServerCertificate="yes",
Port = 1433)