PDA

View Full Version : Connection With database



sudheer168
22nd December 2010, 06:03
Hi every body ,
I am using Qt4.4.3 , VS2005 . I wrote a code to connect to database . The is as follows .




QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("appolice");
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("root");
db.setPort(3307);
if(!db.open())
QMessageBox::information(this,"","Database Connection Failed");



I create one QT GUI app and used this code to connect to database , I am able to connect . But I created one more new Qt GUI app where I used same code to connect to data base but it is not able to connect . I didn't get why it is connecting in one application and why it is failed to connect in another application.
Please help me to make connect .

Regards,
Sudheer.

ChrisW67
22nd December 2010, 06:44
On the same machine?

sudheer168
22nd December 2010, 08:50
Yes on the same machine and same environment.

Regards,
Sudheer .

faldzip
22nd December 2010, 08:53
And what's the console output?
Or instead "Database connection failed" display


db.lastError().text()

sudheer168
22nd December 2010, 09:18
Hi , the error message is as follows


Can't connect to MySQL server on 'localhost'(1002)QMYSQL:Unable to connect