skip to Main Content

I am attempting to connect to a SQL Server from an Azure Databricks notebook using the pyodbc Python library. When I run the query, I encounter the following error:

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

Before executing the query, I tried to install the ODBC driver using the following commands:

%sh
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/ubuntu/22.04/prod > /etc/apt/sources.list.d/mssql-release.list
sudo apt update
sudo apt-get install -y msodbcsql17

However, I received these warning messages:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   983  100   983    0     0  10611      0 --:--:-- --:--:-- --:--:-- 10684
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
E: This command can only be used by root.
bash: line 2: /etc/apt/sources.list.d/mssql-release.list: Permission denied
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required

This is the cluster configuration I am currently using.

Summary
1-2 Workers 14-28 GB Memory  
4-8 Cores 1
Driver 14 GB Memory, 4 Cores
Runtime 14.3.x-scala2.12
Unity Catalog, Standard_DS3_v2, 1–3 DBU/h

Could you assist me in installing the ODBC driver on the Databricks cluster mentioned above?

2

Answers


  1. there are the way thay I install ODBC Driver 18 for SQL Server, I sure it’s the same, and pretty sure that you can work with 18 without changing your code.

    sudo apt-get --assume-yes install unixodbc
    sudo curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
    sudo curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list
    sudo apt-get update
    sudo ACCEPT_EULA=Y apt-get --assume-yes install msodbcsql18
    sudo ACCEPT_EULA=Y apt-get --assume-yes install mssql-tools18
    sudo apt-cache search msodbcsql
    sudo apt-cache search mssql-tools
    sudo echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
    sudo source ~/.bashrc
    
    Login or Signup to reply.
  2. From the Microsoft documentation:

    curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
    curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
    sudo apt-get update
    sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search