QODBC driver not loaded
-
Hi
in the code below i have a problem with addDatabase("QODBC");
it seems that my computer doesn't recognize QODBC how can i find the correct name for adding database i use microsoft sql server 2008 R2
@#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString servername = "TEST\EGHALSQL";
QString dbname = "Test";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
db.setDatabaseName(dsn);
if(db.open())
{
qDebug() << "Opened";
db.close();
}
else
{
qDebug() <<"Error = "<<db.lastError();
}
return a.exec();
}@ -
"According to this paragraph here":http://qt-project.org/doc/qt-4.8/sql-driver.html#qodbc you need to configure a ODBC connection in the ODBC connection manager in the control panel.
The important part readsbq. Be aware that when connecting to an ODBC datasource you must pass in the name of the ODBC datasource to the QSqlDatabase::setDatabaseName() function rather than the actual database name.
Bonus chatter: Using ODBC or not, get used to FQDN for the server name. Saves you from many problems in a "real environment".
-
It is (as long as you use something >= XP), you must configure an ODBC connection: http://msdn.microsoft.com/en-us/library/ca6axakh(v=vs.80).aspx on each computer that should connect to the database via ODBC.
-
-
Please be so kind and provide some information.
What Windows version do you use?
Did you test the ODBC connection? How is it configured? Which driver is configured therein?
Can you connect via OSQL?
Do you still use the connection data from you initial post? If yes, it won't work. If no, what do you use now?
What Qt library version do you use?
32bit or 64bit?
The latter one could be important, because the "database driver must exist":http://communities.bentley.com/other/old_site_member_blogs/bentley_employees/b/allen_brown_bentleys_blog/archive/2009/03/04/32-bit-database-connectivity-on-a-64-bit-os.aspx for the same "bitness" of your application.After all that is checked, it could still be a "bug":https://bugreports.qt-project.org.
-
[quote author="zidom" date="1350898907"]I add odbc
!http://dl.2rialy.ir/ZiDoM-Ups/91/odbc.JPG(odbc)!
but i still have this error
!http://dl.2rialy.ir/ZiDoM-Ups/91/sql.JPG(error)![/quote]
When I did this I also specified DSN in the string I passed to setDatabaseName(). In your case that would be ZiDoM (according to your pic) . The string should look smthng like this:
@"DRIVER={SQL Native Client};DSN='ZiDoM';SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;"@
P.S. I am not quite sure about the string syntax. I will post the one I used tommorow when I get to work. -
This is the string that works fine for me:
@QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={SQL Server};DSN='PlaneTraj';SERVER=DB-SERVER;DATABASE=RealPlanesData;");@
My user DSN (that I added using C:\Windows\SysWOW64\odbcad32.exe) name is PlaneTraj and its Driver is SQL Server; in your case these are ZiDoM and SQL Server (according to your pic).
Try using Driver={SQL Server} instead of yours DRIVER={SQL Native Client} -
Look inside the folder located somewhere like: C:\Qt\4.8.2\plugins\sqldrivers. See if it contains ODBC drivers.
I have the following files in this folder:
qsqlite4.dll qsqlite4.exp qsqlite4.lib qsqlited4.dll
qsqlited4.exp qsqlited4.ilk qsqlited4.lib qsqlited4.pdb
qsqlodbc4.dll qsqlodbc4.lib qsqlodbcd4.dll qsqlodbcd4.lib
qsqlpsql4.dll qsqlpsql4.lib qsqlpsqld4.dll qsqlpsqld -
looks like your app for some reason can't locate theese files. have a look at this http://doc.qt.digia.com/latest/deployment-plugins.html
-
no, I don't know what .exp files are for, but I don't think it's the problem. I mean if you have all the rest qsqlodbc files in \sqldrivers and QSqlDatabase::drivers() doesn't give QODBC in the list, then maybe your app can't locate them in this folder?
does QSqlDatabase::drivers() return anything or the list is epmpty? if it does what is it? -
The only thing I can think of: make a backup of your \sqldrivers or just rename it and try to replace it with mine:
http://zalil.ru/33883387/554c07b0.508763d8/sqldrivers.zip
I am using qt4.8.3 though -
Hi
i made some changes
then i could connect to database
@#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("LOCALHOST\SQLEXPRESS");
db.setDatabaseName("mydsn32");
if(db.open())
{
qDebug() << "Opened";
db.close();
}
else
{
qDebug() <<"Error = "<<db.lastError();
}
return a.exec();
}
@
i made a dsn and i used QSQLITE but i can not still use QODBC but its better than nothing