[SOLVED]: addDatabase with connectionName problem
Hello again!
I have strange problem while dealing with SQLite database. Everything seem so be all right when I open it like this:
Code:
QString dbase_path
= app_path
+ "/base.bz";
{
base.setDatabaseName(dbase_path);
base.open();
if(base.isOpen() != true){
QMessageBox::critical(this,
"Error",
"Base is not open.");
}
else {
// the database is opened
// create data table
QSqlQuery sql_create_table
("CREATE TABLE IF NOT EXISTS data (id INTEGER PRIMARY KEY, date TEXT, ...)");
...
}
base.close();
}
Except when I try to reconnect I get alert:
Quote:
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Data is correctly writen and extracted to and from database.
In docs it is writen, that I must use connectionName to avoid this error. I change:
and add after I close the database. The alert now say:
Quote:
QSqlQuery::exec: database not open
, nothing is writen to the database. base.isDriverAvailable say, it is not...query.lastError() say Driver not loaded. However base.isOpen() say it is open!
What am I doing wrong? I am using Qt 4.5 that came with Fedora 12, sqlite driver is present (at least it was instaled with fedora and in use without connectionName it is working).
Regards,
Luka
Re: addDatabase with connectionName problem
As You have set a name for Your data base connection You will need to specify a connection for the Query to use.
QSqlQuery::QSqlQuery ( const QString & query = QString(), QSqlDatabase db = QSqlDatabase() )
Code:
qry.prepare("....");
Re: [SOLVED]: addDatabase with connectionName problem
That solved my problem. Thank you for fast replay.
Luka
Re: [SOLVED]: addDatabase with connectionName problem