MS SQL Server 2008 with Qt
-
wrote on 9 Jun 2012, 00:35 last edited by
Hi,
I'm trying to connect Qt to MS SQL Server 2008 R2. I already have compiled the ODBC driver and I think it is ok.
This is the code I'm using:
@
qDebug() << "Drivers: "<<QSqlDatabase::drivers();
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("ze-w7\SQLExpress");
db.setDatabaseName("tempdb");
db.setUserName("sa");
db.setPassword("123456");
if(!db.open()){
qDebug()<<"ERROR: "<<QSqlError(db.lastError()).text();
} else {
qDebug()<<"Ok";
}@But I always getting this error:
Drivers: ("QSQLITE", "QODBC3", "QODBC")
ERROR: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"What should I do?
-
wrote on 9 Jun 2012, 11:24 last edited by
Maybe instead of
@db.setHostName("ze-w7\SQLExpress");@you must write
@ db.setHostName("ze-w7\SQLExpress");@
Or try write this code:
@QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={SQL Server};Server=ze-w7\SQLEXPRESS;Database=tempdb;");
db.setUserName("sa");
db.setPassword("123456");
if(!db.open()){
qDebug()<<"ERROR: "<<QSqlError(db.lastError()).text();
} else {
qDebug()<<"Ok";
} @ -
wrote on 9 Jun 2012, 13:18 last edited by
really thanks :)
Used the code you suggest and works :D
1/3