[GIS] Error QODBC driver not loaded when trying to connect to an MSSQL database from QGIS 3.4.3 (Ubuntu)

odbcqgissql server

I have installed QGIS Desktop (latest one: 3.4.3 Madeira) along with the unixODBC-dev for SQL Server 2017 (following instructions here). I used sqlcmd from msql-tools and successfully connected to the database server. I opened QGIS Desktop and when I tried to connect to an MSSQL database I received the following message:

Warning: QSqlDatabase: QODBC driver not loaded 
Warning: QSqlDatabase: available drivers: QSQLITE QSPATIALITE

I went searching for a driver and I found out that I am supposed to build the driver (!).

Assuming that QGIS Desktop is loading the available drivers from /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers, I wen on and installed Qt5.10.1, built the ODBC driver using these instructions and copied the resulting libqsqlodbc.so to the /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers.
This directory now contains the following:

-rw-r--r--  1 root root  65048 Apr 12  2018 libqsqlite.so
-rwxr-xr-x  1 alas root 123784 Jan  4 20:03 libqsqlodbc.so*
-rw-r--r--  1 root root  71832 Dec 22 06:50 libqsqlspatialite.so

I run again QGIS Desktop, I tried again to connect to the database server and I got again the same error.

My questions are:

a. Is there an easy way to add the QODBC driver to QGIS Desktop?

b. Am I doing something wrong above?

c. IS THERE ANY way to make QGIS Desktop in linux work with a SQL Server???

Best Answer

The only workaround I found is the one mentioned in my comment above and since there is no answer I think it is the only way of acquiring the library without building it.

So follow these steps:

  1. go to https://hub.docker.com/r/qgis/qgis/tags
  2. find the release you are interested in (either final-xxx or release-xxx)
  3. download the image (docker pull) and create a container
  4. navigate to /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers and copy out the library