Error message (ODBC) "Driver not loaded" after upgrade from Qt 4.6.1 to 4.7.3
-
Hi,
I'm using a simple WinXp 32-bit machine with MS VC Express for developing with Qt.
After upgrading from Qt 4.6.1 to Qt 4.7.3 and recompiling my source code the QSqlDatabase::open() function fails with error message "Driver not loaded". My code for this kept unchanged and nothing else in the environment has been changed except the environment variable "QTDIR". It is now pointing to the QT 4.7.3 "home directory" instead to QT 4.6.1 "home directory".@
QSqlDatabase m_db;
m_db = QSqlDatabase::addDatabase("QODBC");
m_db.setDatabaseName(databaseName);
m_db.setUserName(userName);
m_db.setPassword(password);QSqlError m_lastError;
bool ok = m_db.open();
if (!ok)
{
m_lastError = m_db.lastError(); // returns "Driver not loaded"
}
@The drivers check with debug instruction
@
QString s( QSqlDatabase::drivers().join( "." )) ;
@
shows in Qt 4.6.1 "QSQLITE.QODBC3.QODBC", but in Qt 4.7.3 only "QSQLITE".
I have no idea why Qt 4.7.3 does not load the ODBC drivers.Any help is very welcome.
Regards
o2t2 -
Check the "documentation":http://developer.qt.nokia.com/doc/qt-4.7/sql-driver.html#id-9b35bbe5-e3f8-4d40-b01a-08db65bd5f40 here.
-
Googeled a little bit and found this
http://doc.qt.nokia.com/latest/sql-driver.html
section "QODBC for Open Database Connectivity (ODBC)"
After the qmake command all works fine.
Thanks for help, Andre.
Regards
o2t2
-
Oh, one's more, Andre:
Neither in the %QTDIR%\plugins\sqldrivers directory nor in the src\plugins\sqldrivers\odbc directory there are no odbc driver dlls or libs.
Where they are ? (Searching in windows explorer does not bring a result...)
Why does it work now ?Background: The drivers have also to be installed at customer site...
-
They should appear in QTDIR\plugins\sqldrivers. If they do not, then something wend wrong with building them, I think.
If you install them at your customers site, I would recommend you do not install Qt as a shared library, at least not if Windows is your target platform (most likely when using ODBC). Instead, put Qt libs in the same directory as the executable, and the plugins you need in folders with the names corresponding to what you find inside QTDIR\plugins (that is: ommit the plugins\ directory level itself). That way, your app will find the right Qt libraries, and Qt will find its plugins without you having to do anything else.
-
Andre,
the "plugins\sqldrivers" directory do not have any odbc files. Crazy.
But i looked once more into the command window where I called qmake and nmake and I see, that nmake failed because the nmake command was not found on the system. May this be the cause for missing odbc dll in "plugins\sqldrivers" ?
If yes: Where resides the nmake? Again: Searching in windows explorer does not bring a result… -
Next question related to this thread: The genration of the driver succeeded and they work fine inside the development environment (Win XP, MSVC2008).
Copied the generated exe and dlls to the runtime environment (MS 2008 Server R2), installed the data source (ODBC) as well as in the development environment.The same error message “Driver not loaded" occurs. So I copied the qsqlodbc.dll too. Same error message. What's wrong ?
Regards
o2t2
-
@
QString ipserver,LoginName,database,Pass;
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MyDatabase");db.setDatabaseName("DRIVER={SQL Server};Server="+ipserver+";Database="+database+";Uid="+LoginName+";Port=1433;Pwd="+Pass+";WSID=");
if(db.open())
{
qDebug() << "Opened";
db.close();
}
else
qDebug() << "Error" << db.lastError().text();
@
the WSID =. “is used to hide the client machine to the database server log ,is optional .