Connect SQL Server with QODBC Driver
-
Hello, I'm going to make an application with Qt Widget (Version 6.7.0) which can connect and communicate with SQL Server. There are 2 requirements with Database connection:
- My application can deploy in both Window (MSVC19) and Android (Qt Android) environment.
- I used QODBC Driver (Microsoft ODBC Driver 17 for SQL Server) to connect with database.
The problem:
-
When I deploy on Window (MSVC2019) environment, I must to install ODBC Driver and Register it in Window System. If not, the connect to SQL Server will be failed due to ODBC Driver is not registered, or not found ODBC Driver.
-
But I confuse that if I want to deploy my application on any device but no need to care about the precondition for Database connection:
Ex: When I execute my app with debug/release on any device or any environment (Window-MSVC19 or Android) it always successful although that device have ODBC Driver or not.
My question is:
- Is there any way to build QODBC and it's relevant to a dynamic library (.dll or .so) so that I can attached it into my app workspace as a third-party lib? Then any device can connect to Database SQL Server after clone source code and no need to do anything else?
- If yes, please help me to archived it. (My Qt Version is 6.7.0)
Thank you for your help.
-
Use an installer and install the odbc driver in there.
-
Don't know so much about ODBC versions on Android, but on Windows Microsoft keeps updating it, i.e. ODBC Driver version 17 is most likely installed on all Windows 10 and 11 PCs.
It's pretty easy to check if it's installed, look for the version installed in the registry:
#include "qsettings.h" ... for (auto group : QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI", QSettings::NativeFormat).childGroups()) qDebug() << group; ... On my vanilla Windows 11 I get: "Microsoft Access Driver (*.mdb, *.accdb)" "Microsoft Access Text Driver (*.txt, *.csv)" "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" "ODBC Core" "ODBC Driver 17 for SQL Server" "ODBC Drivers" "ODBC Translators" "SQL Server"
-
@hskoglund said in Connect SQL Server with QODBC Driver:
Don't know so much about ODBC versions on Android, but on Windows Microsoft keeps updating it, i.e. ODBC Driver version 17 is most likely installed on all Windows 10 and 11 PCs.
It's pretty easy to check if it's installed, look for the version installed in the registry:
#include "qsettings.h" ... for (auto group : QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI", QSettings::NativeFormat).childGroups()) qDebug() << group; ... On my vanilla Windows 11 I get: "Microsoft Access Driver (*.mdb, *.accdb)" "Microsoft Access Text Driver (*.txt, *.csv)" "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" "ODBC Core" "ODBC Driver 17 for SQL Server" "ODBC Drivers" "ODBC Translators" "SQL Server"
Hello @hskoglund , did you mean DOBC Driver version 17 will be installed by default in most of Window 10 and 11 PCs?
One more question, if "ODBC Driver 17 for SQL Server" does not contain it output of this loop:
for (auto group : QSettings("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI", QSettings::NativeFormat).childGroups())
qDebug() << group; --> So does it mean my device's system was not register ODBC Driver Version 17? And if so, how can I register it?Thank you
-
@Christian-Ehrlicher said in Connect SQL Server with QODBC Driver:
Use an installer and install the odbc driver in there.
Hello @Christian-Ehrlicher ,
I already installed most of component in online installer, and seem like the QODBC was installed in my sqldrivers.
But I'm more concerned about how can I bunded it and deploy this driver on another device (Like Android/Linux).
Could you please share me some guide to do that?
Thank you very much.
-
@VuChu said in Connect SQL Server with QODBC Driver:
I already installed most of component in online installer, and seem like the QODBC was installed in my sqldrivers.
@Christian-Ehrlicher was talking about Microsoft ODBC driver, not QODBC...