1

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. enter image description here

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 of Test Connection (see this). Regardless of how the form is submitted, the QGIS log panel shows INFO Testing connection : …… and then WARNING 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 for pyodbc 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
1
  • I don't believe that there is a "native" MSSQL QGIS "provider" for Linux, but only on Windows QGIS. I was able to do something similar (accessing MS SQL data) but with a python QGIS script running on Docker Linux with the qgis/qgis image from Docker hub. I used an "ogr" data provider with a MSSQL connection string, which uses the default MS SQL ODBC driver that comes built-in with the QGIS provided version of GDAL/OGR. You may be able to use a GDAL/OGR vector data connection to MS SQL data within the Linux QGIS UI, but I was unable to quickly succeed with that.
    – Andrew
    Commented Nov 22, 2021 at 19:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.