Similar problem as here and elsewhere...
When I try to Add MSSQL Spatial Layer
to connect to an Azure-hosted MS SQL Server database, I get Error opening connection: Driver not loaded Driver not loaded
no matter what I try, as shown below. I have never seen the OK
button enabled. I am using Pop!_OS 21.04 and QGIS 3.22.0-Białowieża (64-bit). Using QGIS on a separate Windows machine, I do not have this problem using the same interface.
In QGIS under Settings > Options > Data Sources > GDAL > Vector Drivers both ODBC
and MSSQLSpatial
are checked. I have tried unchecking one or the other, restarting QGIS, and trying again. Likewise ogrinfo --info --formats
shows both. I know the host, username, and password are correct because I can use them to connect in Azure Data Studio from the same machine (at the same IP).
I have tried:
- Clicking
List Databases
instead ofTest Connection
(see this). Regardless of how the form is submitted, the QGIS log panel showsINFO Testing connection : ……
and thenWARNING Error opening connection : Driver not loaded Driver not loaded
. - Adding a dummy
Provider/DSN
and editing in Advanced settings as per this (OK
button never enabled) - Doing
sudo apt-get install unixodbc unixodbc-dev tdsodbc freetds-dev
and then configuring ODBC/FreeTDS with updated versions of these settings in various combinations. - Providing a full connection string using FreeTDS for
Provider/DSN
that works forpyodbc
within a Debian Docker container with the same approach:DRIVER=FreeTDS;SERVER=xxxxxx.database.windows.net;PORT=1433;DATABASE=xxxxxx;UID=kfisher;PWD=xxxxxx;TDS_VERSION=8.0
- Installing native MS ODBC driver following these instructions and then editing my odbc.ini (tried in both /etc/odbc.ini and /usr/local/etc/odbc.ini) with settings based on the QGIS test script here.
- Searching QGIS documentation, Stack Exchange, and the internet at large. Unsurprisingly, connecting to PostgreSQL from QGIS is straightforward and well documented, but connecting to MSSQL/Azure is not.
My current odbc files (redacted):
/usr/local/etc/odbcinst.ini:
[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
/usr/local/etc/odbc.ini:
[xxxxxxSQLServer]
Description = xxxxxx SQL Server
Driver = FreeTDS
Server = xxxxxx.database.windows.net
ServerName = xxxxxxSQLServer
UID = kfisher
PWD = xxxxxx
/etc/freetds/freetds.conf:
[xxxxxxSQLServer]
host = xxxxxx.database.windows.net
port = 1433
tds version = 7.4