PDA

View Full Version : Connect To Sql Server With QT



METEOR7
6th December 2011, 16:24
Hi
How I Connect To SQL Server DataBase With QT
(I Tested QODBC)But Driver Not Loaded
Thanks

ChrisW67
7th December 2011, 00:40
QODBC for Open Database Connectivity (ODBC)
Make sure the ODBC plugin is built and present on your machine: is should show in the output of QSqlDatabase::drivers().
Make sure a suitable SQL Server ODBC driver is installed on your machine.
Make sure your ODBC DSN is set up/correct.

Only the first point has much to do with Qt.

lekhrajdeshmukh
7th December 2011, 10:59
Hello Metor,
First of all you need to check that respective Qt odbc driver is available or not on path "C:\Qt\2010.05\qt\plugins\sqldrivers".At this path following file shoulb be present to make connectivity with sql server DB.
libqsqlodbc4.a
libqsqlodbcd4.a
qsqlodbc4.dll
qsqlodbcd4.dll

If above files are not present then you need to build odbc driver for your QT and after that you need to create DSN for your odbc driver.

METEOR7
9th December 2011, 13:28
Thanks For All But How I Do That

lekhrajdeshmukh
12th December 2011, 05:49
Use Below code to check DB connectivity If driver is not present then it will throw the error.
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("DSNName");
db.setHostName("SystemHostName");
db.setDatabaseName("DSNName");
db.setUserName("DBUserName");
db.setPassword("UrDBpassword");

//Checking DB connection
if(!db.open())
{
QMessageBox::critical(0,QObject::tr("DATABASE OPEN"),db.lastError().text());
return false;
}


return true;
}

ChrisW67
13th December 2011, 02:22
Thanks For All But How I Do That

How do you do what? Check that the Qt driver plugin exists, build the Qt plugin, check that a suitable MS SQL Server ODBC driver exists, build a suitable ODBC DSN, check that the connection is working...?

The first two items are covered in my last post and the page I linked to.

METEOR7
13th December 2011, 13:39
How I Build Plugin Please Explain Details

Thanks