PDA

View Full Version : Qt application connection to microsoft SQL database 2008



user_mail07
10th May 2011, 01:10
Hi,
I am trying to connect my application to Microsoft SQL Server managment studiio.

First of all if I do following statement to print drivers.


qDebug << QSqlDatabase::drivers();

It prints "QSQLLITE", "QODBC","QODBC3".

I have attached file as screenshot to display what database i am trying to connect.

Now I try to connect


QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("db1");
db.setHostName("localhost");
db.setUserName("test");
db.setPassword("test");
bool ok = db.open();

if( db.open() )
{
qDebug( "Database successfully opened, now able to query" );

}
However my connection fails. I am not quite sure if QDBC3 drivers works fine with Microsoft SQL Server Management studio 2008.

I have seen at some other posts that lot of other people used syntax like this while setting database name


db.setDatabaseName("DRIVER=FreeTDS;SERVER=localhost;Port=1433;DATABASE =db_test;TDS_Version=8.0;uid=SomeUser;pwd=SomePass word");

Which drivers are compatible with Microsoft SQL Server Management studio 2008.

If somebody can guide me what i am doing wrong here that would be great?63916391

user_mail07
10th May 2011, 18:15
Can you somebody please help me here? I have attached screenshot to display what database i am trying to connect.

jpujolf
11th May 2011, 08:52
You haven't tell us which Qt version are you using.

I've found this bug (http://bugreports.qt.nokia.com/browse/QTBUG-14808) some time ago.

If your version is < 4.7.0

Try changing this ( it works for windows ) :


db.setDatabaseName ( "DRIVER={SQL Server};SERVER=localhost;DATABASE=db1" );

and it must work.

NOTE : Also, telling us which message error gives to you ( using db.lastError().text() ) would allow to give you a better answer to the problem...

user_mail07
11th May 2011, 13:57
Now I am getting following error.


0x00f90c4a " [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"

Qt version is 4.5.2