'Connecting to SQL Server from R studios: "Error: nanodbc/nanodbc.cpp:983: 00000: [unixODBC][Driver Manager]Can't open lib 'driver' : file not found"

I am trying to connect to SQL Server from Rstudio. I get the following error.

> odbc::odbcListDrivers() 
                           name   attribute                                   value
1 ODBC Driver 13 for SQL Server Description Microsoft ODBC Driver 13 for SQL Server
2 ODBC Driver 13 for SQL Server      Driver    /usr/local/lib/libmsodbcsql.13.dylib
3 ODBC Driver 13 for SQL Server  UsageCount    


library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
                  Driver = "ODBC Driver 13 for SQL",
                  Server = "130.440.220.502",
                  Database = "CI_Temp",
                  UID = "user_x",
                  PWD = rstudioapi::askForPassword("Database password"),
                  Port = 1433)

Error: nanodbc/nanodbc.cpp:983: 00000: [unixODBC][Driver Manager]Can't open lib 'driver' : file not found 

Any help will be appreciated. Thanks in advance



Solution 1:[1]

You need to use Driver = "ODBC Driver 13 for SQL Server"

library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
                  Driver = "ODBC Driver 13 for SQL Server",
                  Server = "130.440.220.502",
                  Database = "CI_Temp",
                  UID = "user_x",
                  PWD = rstudioapi::askForPassword("Database password"),
                  Port = 1433)

Solution 2:[2]

I go for Driver = "SQL Server", it works for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 asepulvedar
Solution 2 Dmitry Ishutin