Results 1 to 5 of 5

Thread: QSQLITE | unable to establish connection

  1. #1
    Join Date
    Aug 2006
    Location
    Chennai, India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QSQLITE | unable to establish connection

    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.

    Qt Code:
    1. QSqlDatabase *m_db = QSqlDatabase::addDatabase("QSQLITE");
    2. if(!m_db->open())
    3. {
    4. m_db->setHostName( "localhost" );
    5. m_db->setDatabaseName("ResumeDataBase");
    6. m_db->setUserName( "root" );
    7. m_db->setPassword("");
    8. }
    9.  
    10. if ( ! m_db->open( ) )
    11. {
    12. QSqlError l_sqlError = m_db->lastError();
    13. QString l_sqlErrorString = l_sqlError.text();
    14. QMessageBox::information(this, "RTS", l_sqlErrorString);
    15. }
    To copy to clipboard, switch view to plain text mode 

    How to rectify this problem?
    Last edited by jpn; 1st July 2008 at 08:03. Reason: missing [code] tags

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSQLITE | unable to establish connection

    If I'm not mistaken, then SQLite's database is created without specifying its owner. Try to remove these lines

    Qt Code:
    1. m_db->setUserName( "root" );
    2. m_db->setPassword("");
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Aug 2006
    Location
    Chennai, India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSQLITE | unable to establish connection

    Thanks for your reply.

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

  4. #4
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: QSQLITE | unable to establish connection

    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().
    Qt Code:
    1. if(m_db->open())
    To copy to clipboard, switch view to plain text mode 

    Qt 3.8 ... . Maybe you created the sqlite db with a different (later) version of sqlite.
    Last edited by janus; 1st July 2008 at 11:07.

  5. #5
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSQLITE | unable to establish connection

    Yeah, Janus is right you probably need to do this

    Qt Code:
    1. QSqlDatabase *m_db = QSqlDatabase::addDatabase("QSQLITE");
    2.  
    3. m_db->setHostName( "localhost" );
    4. m_db->setDatabaseName("ResumeDataBase");
    5.  
    6. if ( ! m_db->open( ) ) {
    7. QSqlError l_sqlError = m_db->lastError();
    8. QString l_sqlErrorString = l_sqlError.text();
    9. QMessageBox::information(this, "RTS", l_sqlErrorString);
    10. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

Similar Threads

  1. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  2. QSQLITE Unable to fetch row in create
    By xgoan in forum Newbie
    Replies: 3
    Last Post: 18th October 2006, 14:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.