PDA

View Full Version : QODBC by QT



mirek_zaklosa
5th June 2019, 06:50
Hello,

I've a connection string to ODBC:

Provider=ASAProv.90;Persist Security Info=True;User ID=DBA;Data Source=OCONET

I'm trying to use it by:

QSqlDatabase db;
db = QSqlDatabase::addDatabase("QODBC");
QString connectString = "Provider=ASAProv.90;Persist Security Info=True;User ID=DBA;Data Source=OCONET;";
db.setDatabaseName(connectString);
if(db.open())
{
QMessageBox::about(this,"Connected","Connected");
}else{
QMessageBox::about(this,"NOT Connected","NOT Connected");
}

and I've got "NOT Connected" :(
What I'm doing wrong? :(

Lesiok
5th June 2019, 07:42
If db not open look at QSqlDatabase::lastError.

mirek_zaklosa
5th June 2019, 07:55
I've got:

Driver not loaded

:(

mirek_zaklosa
5th June 2019, 14:12
I've found in Windows 7 "ODBC Configuration":13145

with "MyDRIVER". Test connection display "connection ok".

Now I'm trying connect by using "MyDRIVER":


QSqlDatabase db;
db = QSqlDatabase::addDatabase("QODBC");
QString connectString = "DRIVER={MyDRIVER}";
db.setDatabaseName(connectString);
if(db.open())
{
QMessageBox::about(this,"Connected","Connected");
}else{
QMessageBox::about(this,"NOT Connected","NOT Connected");
QMessageBox::about(this,"NOT Connected",db.lastError().databaseText());
}

And i've got:
"NOT Connected"
"Driver not loaded"

:(

anda_skoa
7th June 2019, 08:28
"Driver not loaded" could mean that the QSql Plugin for QODBC is not present or fails to load.

You should be able to get more information by setting the QT_DEBUG_PLUGINS variable, see https://doc.qt.io/qt-5/deployment-plugins.html#debugging-plugins

Cheers,
_