locus
23rd June 2007, 03:56
I am running two peices of code shown below, both of which are trying to connect to the mysql server (version 5.0.41).
The codes are shown below; one is basically the carbon copy of the other, they are running on the same machine, same operating system.
I am using MVS .NET 2003
The first code (code number one), well thats all there is to it, just a main.cpp file.
The only difference between the two peices of code is that the last one (code number two), is a part of a large project (and as you can see i have commented the inclusion of other files in the project, in an attempt to get the two peices of code exactly alike).
I am using QMessageBox to test the outputs and see whats going on.
From code number one i get a message box telling me that i am connected to the server.
From code number two i get a message box saying : DRIVER NOT LOADED DRIVER NOT LOADED.
If you have any suggestions whatsoever that could explain this, please post.
Thanks in advance for your time.
Here they are:
code number one:
#include <qapplication.h>
#include<QtCore>
#include<QtGui>
#include <QSqlDatabase>
#include <QSqlError>
#include<QString>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
db.setHostName("localhost");
db.setDatabaseName("pabxdb");
db.setUserName("root");
db.setPassword("root");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
const QString stry = "connected";
if(createConnection()){
QMessageBox::information(0, QObject::tr("Database Error"),stry);
} // create database connections
return 0;
}
code number two
#include <QApplication.h>
#include<QtCore>
#include<QtGui>
#include <QSqlDatabase>
#include <QSqlError>
#include<QString>
#include<QStringList>
//#include "global.h"
//#include "mainConsole.h"
//#include "pabxdialog.h"
//bool USER_FLAG; // USER_FLAG GLOBAL VARIABLE ** defined elsewhere as extern **
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
db.setHostName("localhost");
db.setDatabaseName("pabxdb");
db.setUserName("root");
db.setPassword("root");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
const QString stry = "connected";
//const QString stry1 = "driver not found";
if(createConnection()){
QMessageBox::information(0, QObject::tr("Database Error"),stry);
} // create database connections
//mainConsole pabx( 0, 0,0, &app ); // instantiate main console
return 0;
}
The codes are shown below; one is basically the carbon copy of the other, they are running on the same machine, same operating system.
I am using MVS .NET 2003
The first code (code number one), well thats all there is to it, just a main.cpp file.
The only difference between the two peices of code is that the last one (code number two), is a part of a large project (and as you can see i have commented the inclusion of other files in the project, in an attempt to get the two peices of code exactly alike).
I am using QMessageBox to test the outputs and see whats going on.
From code number one i get a message box telling me that i am connected to the server.
From code number two i get a message box saying : DRIVER NOT LOADED DRIVER NOT LOADED.
If you have any suggestions whatsoever that could explain this, please post.
Thanks in advance for your time.
Here they are:
code number one:
#include <qapplication.h>
#include<QtCore>
#include<QtGui>
#include <QSqlDatabase>
#include <QSqlError>
#include<QString>
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
db.setHostName("localhost");
db.setDatabaseName("pabxdb");
db.setUserName("root");
db.setPassword("root");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
const QString stry = "connected";
if(createConnection()){
QMessageBox::information(0, QObject::tr("Database Error"),stry);
} // create database connections
return 0;
}
code number two
#include <QApplication.h>
#include<QtCore>
#include<QtGui>
#include <QSqlDatabase>
#include <QSqlError>
#include<QString>
#include<QStringList>
//#include "global.h"
//#include "mainConsole.h"
//#include "pabxdialog.h"
//bool USER_FLAG; // USER_FLAG GLOBAL VARIABLE ** defined elsewhere as extern **
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
db.setHostName("localhost");
db.setDatabaseName("pabxdb");
db.setUserName("root");
db.setPassword("root");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
const QString stry = "connected";
//const QString stry1 = "driver not found";
if(createConnection()){
QMessageBox::information(0, QObject::tr("Database Error"),stry);
} // create database connections
//mainConsole pabx( 0, 0,0, &app ); // instantiate main console
return 0;
}