PDA

View Full Version : Qodbc



Suths
16th March 2012, 15:18
Hi everyone,

Just wondering if anyone had any guidance for how to get QODBC to work inside visual studio 2008? so far i have downloaded Qt libraries 4.8.0 for Windows (VS 2008, 273 MB), and followed the online instructions for compiling the plugin, navigating to C:\Qt\4.8.0\src\plugins\sqldrivers\odbc, then running qmake odbc.pro, then nmake, however when i try to open a connection to the server I get
'Error "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect" '

Does any one have any ideas my code is as follows:


QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("LOCALHOST\\SQLEXPRESS");
db.setDatabaseName("test");
db.setUserName("...");
db.setPassword("...");

if(db.open())
{
qDebug() << "Opened";
db.close();
}

else
qDebug() << "Error" << db.lastError().text();

marcvanriet
19th March 2012, 01:44
Hi,

I use something like this for opening an Access database. The 'setDatabaseName is more complex then your "test". Maybe there's something similar for an Sql Express database.


QSqlDatabase dbDci = QSqlDatabase::addDatabase("QODBC");
dbDci->setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MSAccess};DBQ=dci.mdb");
dbDci->open();

Regards,
Marc