PDA

View Full Version : ODBC Database plugin is not loading



QPlace
3rd November 2008, 19:49
I am using Qt4.5 preview on Windows with VS2008.

I compiled ODBC driver after QT was compiled. Driver was successfully compiled in /plugins/sqldrivers directory of QT tree.

Now, when I am trying to use ODBC driver in my app, I am getting "Driver not loaded" error message. I added "/plugins" subdirectory under my application directory and copied two dlls from Qt45/plugins/sql drivers to <myprojectpath>\plugins. The files that I copied are:
qsqlodbc4.dll
qsqlodbcd4.dll
and also msvcr90.dll, since dependencywalker did find it in these dlls and I did not have it in the PATH.

I have following code:
QApplication::addLibraryPath(QCoreApplication::app licationDirPath() + "/plugins");
QStringList lp = QApplication::libraryPaths();
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
bool isda = QSqlDatabase::isDriverAvailable("QODBC");
db.setDatabaseName("MyApp");
db.setUserName("sa");
db.setPassword("dbpassword");
bool ok = db.open();

I see that variable lp contains directory with odbc plugins, but variable isda is false and of course variable ok is false also.

I will appreciate any tips or hints that can help me to understand what I am doing wrong...

Methedrine
3rd November 2008, 20:49
Try putting it into plugins\sqldrivers.

If that does not help then check with LDD / DepedencyWalker if you are missing any further libraries.

QPlace
3rd November 2008, 23:09
Did not help. Dependency walker does not show any gross violations. The most important were msvcr90.dll and msvcr90d.dll that I put straight in the plugins\sqldrivers

How can I debug this thing or figure out the reason for this cryptic "Driver not loaded" message? May be I have to call addLibraryPath in some other place? I am at lost :(

jacek
4th November 2008, 00:44
Do you create QCoreApplication or QApplication instance?

QPlace
4th November 2008, 00:47
I created QApplication, not QCoreApplication.

QPlace
4th November 2008, 02:44
Here is what I found (and I don't know how to explain the results):

I added directory where I want to load database plugins to with the call to
QApplication::addLibraryPath("mypath");

Then I call QApplication::libraryPaths(). It returns three paths in that order:

<mypath>
<qtpath\plugins>, where qtpath is a path to the root of QT tree
<application path>

I had ODBC drivers qsqlodbc4.dll in <mypath> directory. Under <qtpath\plugins there is sqlplugins directory which I intentionally left empty. My reasoning was that if I put database drivers into <mypath> directory QT should find them because of addLibraryPath call. That assumption was incorrect; ODBC driver failed to load. Only when I copied ODBC driver back to qtpath\plugins\sqldrivers directory they loaded OK.

Now the question is: Why that is happening?

spirit
4th November 2008, 06:46
did you have the sqldrivers directory in the mypath directory?
PS. the sqldrivers directory must have needed sql drivers.

QPlace
4th November 2008, 12:34
Yes, I did. Each of the directories that QApplication::libraryPaths() returns have
plugins\sqldrivers construct in them. In other words these directories look like:
<mypath>\plugins\sqldrivers
<QTpath>\plugins\sqldrivers
<apppath>\plugins\sqldrivers

Yes, and one other thing: application runs under VC2008 debugger, started from VS2008 IDE.

spirit
4th November 2008, 12:37
and you run debug version of you program and sqldrivers have debug pugins?

QPlace
4th November 2008, 14:12
This is the contents of the directory that all three directories have:

Directory of <path>\plugins\sqldrivers

11/04/2008 09:11 AM <DIR> .
11/04/2008 09:11 AM <DIR> ..
12/08/2006 04:36 PM 37,376 dwmapi.dll
01/24/2004 03:17 AM 25,088 efsadu.dll
08/04/2004 09:56 AM 59,904 mpr.dll
11/07/2007 12:19 AM 655,872 msvcr90.dll
11/07/2007 12:19 AM 1,180,672 msvcr90d.dll
11/03/2008 09:13 AM 71,680 qsqlodbc4.dll
11/03/2008 09:13 AM 134,656 qsqlodbcd4.dll

spirit
4th November 2008, 14:30
these two files must be in sqldrivers directory


11/03/2008 09:13 AM 71,680 qsqlodbc4.dll
11/03/2008 09:13 AM 134,656 qsqlodbcd4.dll


i.e. the structure of you directory must be


yourappdir
|---sqldrivers
| |---qsqlodbc4.dll
| |---qsqlodbcd4.dll
|---yourapp.exe

QPlace
4th November 2008, 15:04
Thank you, that was the problem. So, it is not "plugins/sqldrivers", but "sqldrivers"...