Unable to connect to ODBC through shinyapps.io - r

I build a r shiny app which uses the odbc library to fetch the data from server hosted in public server and shows the result output. It is working perfectly under Win10.
I am using the below code to connect to server:
library(odbc)
con <- dbConnect(odbc(),
Driver = "SQL Server Native Client 11.0",
Server = "****",
Database = "****",
UID = "****",
PWD = "****")
When I hosted the app in www.shinyapps.io it is not working. It shows the error as below:
Warning: Error in : nanodbc/nanodbc.cpp:950: 01000: [unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 11.0' : file not found
I am unable to why it says 'file not found'? The app works perfectly when I run the app using rstudio from my PC.
Please help.
Thanks in advance.
Sumanta

You have to use FreeTDS. I found either using 7.4 or 7.0 version.
try this using odbc:
library(DBI)
library(odbc)
con <- dbConnect(
odbc(),
Driver = "FreeTDS",
Database = database,
Uid = uid,
Pwd = pwd,
Server = server,
Port = 1433,
TDS_Version = 7.4
)
or this usind rodbc:
library(RODBC)
con <- odbcDriverConnect(
'Driver=FreeTDS;
TDS_Version=7.4;
Server=<server>;
Port=<port>;
Database=<db>;
Uid=<uid>;
Pwd=<pw>;
Encrypt=yes;
TrustServerCertificate=no;
Connection Timeout=30;')

Related

Trying to work on R using Azure ML Studio Notebook and facing challenges with ODBC package

I am trying to work on R notebook on ML Studio. Using regular python is easy and works as expected but with R i am facing challenges.
While trying to connect to MS SQL database using odbc() :
library(odbc)
con <- dbConnect(odbc(),
Driver = "SQL Server",
Server = "server",
Database = "db",
UID = "user",
PWD = "password",
Port = 1433)
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
As suggested in some posts, i have also tried replacing Driver = "SQL Server", with Driver = "ODBC Driver 11 for SQL Server". But i see similar error
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 11 for SQL Server' : file not found
Traceback:
Please suggest a work around.
We can assign the Driver as the version of the SQL server and get the password using the API call.
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = "your server IP address",
Database = "Database name",
UID = "User ID",
PWD = rstudioapi::askForPassword("password"),
Port = port_number_under_user)
In some cases, Driver = "SQL Server” will also work fine. If not functioning. Use the above code block.

How to connect SQL Server with Rstudio?

I have downloaded Microsoft SQL Server on my Mac with the Docker image as described here, and also I have downloaded the database AdventureWorks2019 as an example which I found it here.
So far so good. Everything works fine.
Now I want to import this database in my RStudio.
I followed the instructions which I found here.
So I opened RStudio and I typed the following:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "localhost",
Database = "AdventureWorks2019",
uid = "sa",
pwd = "<YourStrong#Passw0rd>",
port = 1433,
Trusted_Connection = "True")
I get an error
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
Meanwhile the container in Docker is active and the localhost is active (green) in MS SQL.
I searched on the web for similar errors on Mac and I am more confused.
Any help? Someone?
This works for me:
con <- DBI::dbConnect(
odbc::odbc(),
Driver = "SQL Server",
Server = "server",
Database = "database",
UID = "uid",
PWD = "pwd"
)
I don't think you need Port and Trusted_Connection?

MongoDB Connection in Rstudio with odbc

I'm trying to connect to a mongoDB database using library(odbc) in R. First I installed the driver from here and then I have used the following method:
con <- dbConnect(odbc::odbc(),
Driver = "MongoDB ODBC 1.3.0 Unicode Driver",
Server = "xxxxx",
AuthMechanism = "SCRAM-SHA-1",
Port = 27017,
Database = "test",
UID = "utest",
PWD = "ptest"
)
However the following error will happen:
Error: nanodbc/nanodbc.cpp:983: 08S01: [MySQL][ODBC 1.3(w) Driver]Lost
connection to MySQL server at 'waiting for initial communication
packet', system error: 10060
I would appreciate any help.Thanks

Conntecting to SQL Server by R on macOS

I have a problem to connect to my external sql server database on R. I am working on macOS. I tried to do everything as in tutorial: LINK
My code:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(), Driver = "SQL Server", Server = "server", Database = "DataBaseName", UID = "Login", PWD = "password", Port = 1433)
but I still get this same error:
ERROR: nanodbc/nanodbc.cpp:950: 01000: [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
Does anyone know how to solve this problem? I will be very grateful!

RODBC odbcDriverConnect() Connection Error in shiny R but not in Rstudio

I'm trying to use
odbcDriverConnect("driver={SQL
Server};server=IP;database=DBNAME;uid=username;pwd=password")
to connecting sql server database from shiny R,
but its result is -1.
I run the same code in R studio and get results normally, what's the problem?
For testing more I tried this one:
con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "IP",
Database = "dbname",
UID = "username",
PWD ="password",
Port = Port)
But again it runs in R studio but not in shiny and gets this error:
nanodbc/nanodbc.cpp:950: IM002: [unixODBC][Driver Manager]Data source name
not found, and no default driver specified

Resources