QODBC
-
Hi
I have problem with creating QODBC data base. I installed qt 5.6 (32bit) on windows. I always face this "QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7"I checked "C:\Qt\Qt5.6.0\5.6\mingw49_32\plugins\sqldrivers" and noticed that no QODBC dll files exists in this folder. I'm wondering which tool should be installed to solve this problem.
I downloaded Qt Open Source 5.6. May this version haven't accurate proficiency requirements for using ODCB?
-
@lina
Have a look here http://doc.qt.io/qt-5.6/sql-driver.html#qodbc-for-open-database-connectivity-odbcAs far as i know, in newer versions of Qt ( > 5.6.0) the ODBC driver is installed by default (https://bugreports.qt.io/browse/QTBUG-49420). So you can also download the newest version of Qt, if you do not want to build it by yourself.
-
@michalos
Hi Michalos
this is my code:QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName(":memory:");
qDebug() << "db open" << db.open();// create a table in the memory DB QSqlQuery q_create = db.exec("CREATE TABLE qdn (id int, name varchar(50))"); qDebug() << "create: " << q_create.lastError(); // populate with some data QSqlQuery q_insert(db); q_insert.prepare("INSERT INTO qdn (id, name) VALUES (:id, :name)"); q_insert.bindValue(":id", QVariant::fromValue(1)); q_insert.bindValue(":name", "Volker"); qDebug() << "insert volker: " << q_insert.exec(); q_insert.bindValue(":id", QVariant::fromValue(2)); q_insert.bindValue(":name", "Root"); qDebug() << "insert root: " << q_insert.exec(); // create a new file based database and attach it // to the existing Qt DB handle QString sqlAttach = QString("ATTACH DATABASE '%1' AS fileDB") .arg(QDir::toNativeSeparators("../sqlModel/qdn.db")); QSqlQuery q_attach = db.exec(sqlAttach); qDebug() << "attach: " << q_attach.lastError(); // create the table in the file based DB as a copy // of the in memory DB QSqlQuery q_create_fdb = db.exec("CREATE TABLE fileDB.qdn AS SELECT * from qdn"); qDebug() << "create select: " << q_create_fdb.lastError();
also this is ODBC driver pic on my computer :
also this is sqldrivers in QT installation folder:
-
Hi Devopia53
I coulden't find the path : Src\qtbase\src\plugins\sqldrivers\odbc on my computer. however I have the odcb driver in odcb data source administrator window. should I install qt source seprately? where can I download qt source for windows?
-
I'm no expert on ODBC, but I had to connect to a Netezza DB last week and all it took was to:
- install the Netezza ODBC driver
- configure the ODBC connection in windows (%windir%\system32\odbcad32.exe) and add the DNS user
- followed the instruction on http://doc.qt.io/qt-5.7/sql-driver.html
a) 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.
b)With Microsoft SQL Server the result set returned by a stored procedure that uses the return statement, or returns multiple result sets, will be accessible only if you set the query's forward only mode to forward using QSqlQuery::setForwardOnly().
Unfortunetly I don't have the code right now.
I will try to post it in the next 12h. -
@lina
You just need reinstall qt 5.6.0 and in select components step ,choose select all ,or choose Sources in subset of Qt5.6
after installation you have src folder in C:\Qt\Qt5.6.0\5.6 and you can find odbc folder in there@Devopia53
It isn't missing from version 5.6.0