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
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.
From the Microsoft documentation: