PDA

View Full Version : problem in using QODBC ???????



saeed
12th November 2011, 14:12
hi
i want to use QODBC for use ms Access database.



QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=Data.mdb");
if(!db.open())
QMessageBox::information(this,"",db.lastError().text());



but have this error : QSqlError(0, "QODBC3: Unable to connect", " [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified").

please help me for solve this problem.
Thanks.

Rhayader
12th November 2011, 20:21
Is your Data.mdb in the same directory with your executable? Try setting a full path and see if it throws an error.

ChrisW67
14th November 2011, 00:50
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=Data.mdb"); // <<<<<< DSN=''
if(!db.open())
QMessageBox::information(this,"",db.lastError().text());

but have this error : QSqlError(0, "QODBC3: Unable to connect", " [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified").

I have emphasised the two pieces of information that I would put together. Do you really have a predefined data source (in your ODBC admin) that is called ''?

Here is an ODBC connection string that I use on a legacy database:

// construct an ODBC connection string for the Access Db
QString conn = QString("Driver={Microsoft Access Driver (*.mdb)};Dbq=%1;Uid=Admin;Pwd=;").arg(fileName);

but you could start by just removing the DSN=''.

saeed
15th November 2011, 23:10
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=Data.mdb");
if(!db.open())
qDebug() <<db.lastError();




I use this code and got my issue was resolved
Thank you for your assistance