Rodolfo Terra


Publication Date: 10 - 27 - 2020


Difficulties in accessing Banco Server
on a Linux Operating System?

SQLServer


I currently work as a data scientist, and I use an AWS Instance to work with RStudio, with Linux operating system.

Windows

If you are working with a Windows operating system and need to connect to a Server Database. Just follow the command:


   #Package

   install.package(“odbc”)

   install.package(“DBI”)

 

   # poderá instalar direto pelo github

   devtools::install_github("r-dbi/odbc”)


After installing the package just access the bank serves:

   library(DBI)

   con <- dbConnect(odbc ::odbc(),

          driver = "ODBC Driver 17 for SQL Server",

          Database = "-x-x-x-x-x",

          UID = "-x-x-x-x-x",

          PWD = "-x-x-x-x-x",

          Port = 1433)


Linux

When in a Linux environment, in the case of an EC2 AWS and install the packages as below:


   #Package

   install.package(“odbc”)

   install.package(“DBI”)

 

   # poderá instalar direto pelo github

   devtools::install_github("r-dbi/odbc”)


After installing the package just access the Serve bank:

And the following error appears:


   library(DBI)

   con <- dbConnect(odbc ::odbc(),

          driver = "ODBC Driver 17 for SQL Server",

          Database = "-x-x-x-x-x",

          UID = "-x-x-x-x-x",

          PWD = "-x-x-x-x-x",

          Port = 1433)


   Error: nanodbc/nanodbc.cpp:983: 00000: [unixODBC]

   [Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found)


We have to go to the terminal, which is on the console side of RStudio and follow the following guidelines that you will be successful.

First, we need to install the UNIXODBC Package, mandatory for all banks.


   # Instale the package unixODBC

   sudo apt-get install unixodbc unixodbc-dev


For SQL Server on Linux, it is recommended to use Microsoft drivers


   # Drivers ODBC do SQL Server

   sudo apt-get install tdsodbc

   # Drivers ODBC ODBC PostgreSQL

   sudo apt-get install odbc-postgresql

   # Drivers ODBC do MySQL

   sudo apt-get install libmyodbc

   # Drivers ODBC do SQLite

   sudo apt-get install libsqliteodbc


If you try to connect to the bank, you may not be able to, but there is little left.


   # at the terminal

   sudo up


Pay close attention now to the version of your Ubuntu operating system


   #Ubuntu 16.04

   curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

   #Ubuntu 18.04

   curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

   #Ubuntu 20.04

   curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list


To then finish the process and have access to the bank successfully


   Exit

   sudo apt-get update

   sudo ACCEPT_EULA=Y apt-get install msodbcsql17

   sudo ACCEPT_EULA=Y apt-get install mssql-tools

   echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

   echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash

   source ~/.bashrc

   sudo apt-get install unixodbc-dev


Now just return to the RStudio console and connect to the Server bank.


SQLServer

Thank you very much

Good job