QODBC/Qt4

调试了很长时间,总是提示说“数据源名称过长”,后来发现问题出在将connStr里的
DRIVER写成Driver了
Qt的ODBC好象对大小写敏感,所以一定要根据DSN里的原样copy过来。

bool UserSoils::connectDb()
{

//create default conn using assigned dbPath
QString connStr=QString(
"DRIVER={Microsoft dBASE Driver (*.dbf)};FIL={dBase 5.0};DBQ=%1")

.arg(dbPath());

//for access
//QString connStr=QString(
// "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=c:xxxx.mdb");
qDebug()<<"UserSoils::connectDb(), connStr ="<< connStr;
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName(connStr);
return db.open();
//qDebug()<<"UserSoils::connectDb(),"<<db.lastError().databaseText();

}

Leave a Reply

Your email address will not be published. Required fields are marked *