Results 1 to 9 of 9

Thread: Sql, dupicate connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Sql, dupicate connection

    1) At the start up I create a connection (default)
    2) If the user wants to open another archive I would open a new connection to that database and make it as default.
    it is also not necessary to make connection default, you can pass needed database in ctors of sql classes.

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

    Default Re: Sql, dupicate connection

    hi,

    i am working with a code like this ...

    Qt Code:
    1. QString path = QFileDialog::getOpenFileName(this,
    2. tr("Path to DB"), qApp->applicationDirPath(), "SQLite (*.sqlite3)");
    3. if(!path.isEmpty()){
    4. QSqlDatabase::database().close();
    5. QSqlDatabase::database().removeDatabase(QSqlDatabase::database().connectionName());
    6. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    7. db.setDatabaseName(path);
    8. if(!db.open()){
    9. QMessageBox::critical(this, tr("Error"), tr("DB Error"));
    10. }
    To copy to clipboard, switch view to plain text mode 

    But I always get the message that the database is still in use. AFAIR you cant get rid of this message with sqlite ... . But the new connection does work.

  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sql, dupicate connection

    I just came up with a method which imitates yours.
    Every time I check the database connection, and if it is ok I open a connection with the name of the filename. More, I use a member variable to track the current database in action.
    In this way, I can always remove the correct database and avoid duplicate connection.

Similar Threads

  1. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 08:42
  2. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  3. Connection with MS SQL
    By manish_pesit in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2006, 07:47

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.