PDA

View Full Version : ODBC to mssql2008express



LordQt
9th March 2009, 12:44
Hello friends,

I have problem to connect to 2008 express Database.



static bool createConnection(QString driver= "QODBC",
QString connectionstr="DRIVER={SQL Server};"
"Server=IP\\Instance;Trusted_Connection=no;"
"Database=Databasename;Uid="";Pwd="";"
)
{
QSqlDatabase db = QSqlDatabase::addDatabase(driver);
db.setDatabaseName(connectionstr);
db.setUserName("");
db.setPassword("");
if (!db.open()) {
QSqlError err = db.lastError ();
QMessageBox::information(0, QObject::tr("Cannot open database"), err.text());
return false;
}
return true;

}

with this code I have no problem to Connect to mssql 2005 but with 2008 it doesn´t connect.

Have anybody an idea????

QPlace
9th March 2009, 14:16
Did you try to connect to 2008 sql with these credentials from some "native" M$soft products/drivers?

Are you using 4.5 with (should be now) LGPL db drivers? I did not check it out myself and very curious to find out.

LordQt
9th March 2009, 15:09
I connect it from my program.

I solve it. It must be



static bool createConnection(QString driver= "QODBC",
QString connectionstr="DRIVER={SQL Server Native Client 10.0};"
"Server=IP\\Instance;Trusted_Connection=yes;"
"Database=Databasename;Uid="";Pwd="";"
)
{
QSqlDatabase db = QSqlDatabase::addDatabase(driver);
db.setDatabaseName(connectionstr);
if (!db.open()) {
QSqlError err = db.lastError ();
QMessageBox::information(0, QObject::tr("Cannot open database"), err.text());
return false;
}
return true;

}


And you have to install the native sql client.
Yes I use Qt4.5.0 ans compile it with the ODBC flag etc..

thanx