PDA

View Full Version : QSQLITE | unable to establish connection



suresh
1st July 2008, 07:55
Hi,

I installed QT 3.3.6

Tried to establish a connection with SQULITE database. But error messages says like
"file is encrypted or is not database error to open the database".

Below is my code.


QSqlDatabase *m_db = QSqlDatabase::addDatabase("QSQLITE");
if(!m_db->open())
{
m_db->setHostName( "localhost" );
m_db->setDatabaseName("ResumeDataBase");
m_db->setUserName( "root" );
m_db->setPassword("");
}

if ( ! m_db->open( ) )
{
QSqlError l_sqlError = m_db->lastError();
QString l_sqlErrorString = l_sqlError.text();
QMessageBox::information(this, "RTS", l_sqlErrorString);
}

How to rectify this problem?

lyuts
1st July 2008, 09:16
If I'm not mistaken, then SQLite's database is created without specifying its owner. Try to remove these lines



m_db->setUserName( "root" );
m_db->setPassword("");

suresh
1st July 2008, 10:15
Thanks for your reply.

I removed those lines and tried again. Still the same error comes.

janus
1st July 2008, 11:03
Hi,
why twice "!"?
I dont know if it makes a difference. But I usually create the db on the stack ...
And maybe first set the database name and then .open().

if(m_db->open())

Qt 3.8 ... . Maybe you created the sqlite db with a different (later) version of sqlite.

lyuts
1st July 2008, 11:17
Yeah, Janus is right you probably need to do this



QSqlDatabase *m_db = QSqlDatabase::addDatabase("QSQLITE");

m_db->setHostName( "localhost" );
m_db->setDatabaseName("ResumeDataBase");

if ( ! m_db->open( ) ) {
QSqlError l_sqlError = m_db->lastError();
QString l_sqlErrorString = l_sqlError.text();
QMessageBox::information(this, "RTS", l_sqlErrorString);
}