Results 1 to 3 of 3

Thread: Using two separate databases over ODBC inside a class fails

  1. #1
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Using two separate databases over ODBC inside a class fails

    I want to use two separate databases over ODBC in my application.

    If I do something like this:

    Qt Code:
    1. db_serno=QSqlDatabase::addDatabase("QODBC");
    2.  
    3. db_serno.setDatabaseName("AccDB");
    4.  
    5. db_serno.open();
    6. db_serno.exec(<SQL_QUERY>); <-- query performs successfully
    7.  
    8. db=QSqlDatabase::addDatabase("QODBC"); // trying to add another ODBC connection to another DB
    9.  
    10. db_serno.exec(<SQL_QUERY>); <-- query fails (last error is: Driver not loaded)
    To copy to clipboard, switch view to plain text mode 

    It seems that second addDatabase() somehow corrupts also the first odbc object. Obviously I am doing something wrong, how can I fix it?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using two separate databases over ODBC inside a class fails

    Hi, the docs for QSqlDatabase::addDatabase() say:
    Warning: If you add a connection with the same name as an existing connection, the new connection replaces the old one. If you call this function more than once without specifying connectionName, the default connection will be the one replaced.
    So try passing a connection name as second parameter to QSqlDatabase::addDatabase().

    Ginsengelf

  3. The following user says thank you to Ginsengelf for this useful post:

    Tiansen (10th June 2022)

  4. #3
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using two separate databases over ODBC inside a class fails

    Quote Originally Posted by Ginsengelf View Post
    Hi, the docs for QSqlDatabase::addDatabase() say:

    So try passing a connection name as second parameter to QSqlDatabase::addDatabase().

    Ginsengelf
    Thank you, that is working!!

Similar Threads

  1. How to Have a class run in a separate thread.
    By sona1111 in forum Newbie
    Replies: 7
    Last Post: 29th August 2013, 07:44
  2. ODBC & FreeTDS qwith Qt 4.7 fails !!
    By jpujolf in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2010, 13:58
  3. Put in a separate thread a method of a class
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2010, 00:45
  4. separate class using an interface
    By qt_gotcha in forum Newbie
    Replies: 7
    Last Post: 3rd March 2010, 22:54
  5. separate Qt class diagram
    By juanrb in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2008, 20:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.