Results 1 to 2 of 2

Thread: multiple pgsql databases in QT with a single QTthread

  1. #1
    Join Date
    Aug 2012
    Posts
    4
    Qt products
    Qt3 Qt4

    Default multiple pgsql databases in QT with a single QTthread

    How to open multiple pgsql databases in QT with a single QTthread with diffrenernt user names of the and IP adderess.
    hi
    I am having to 3 mysql databses at three different IP address with same database name.
    My QT application needs to connect all 3 data base at same time and needs to update the tables of all 3 databases.
    this is my code:
    /* for DB0 */
    QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    db.setHostName("10.2.74.222");

    db.setDatabaseName("MAIN");

    db.setUserName("user1");

    db.setPassword("user111");
    db.setPort(5437);
    if (!db.open())
    {
    qDebug("OPening database fail");
    }

    QSqlQuery query("select *",db);

    if(!(query.exec()))
    {
    qDebug("Cannot execute the query ");
    }
    /* for DB0 */


    /* for DB2 */
    QSqlDatabase db1 = QSqlDatabase::addDatabase("QPSQL");

    db1.setHostName("10.2.74.222");

    db1.setDatabaseName("CPSS_DEC11");

    db1.setUserName("user1");

    db1.setPassword("user111");
    db1.setPort(5437);
    if (!db1.open())
    {
    qDebug("OPening database fail");
    }

    QSqlQuery query1("select *",db1);

    if(!(query1.exec()))
    {
    qDebug("Cannot execute the query verify seccode111");
    }
    /* for DB2 */

    When i am trying to connect all 3 its generating following error:
    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
    This version of PostgreSQL is not supported and may not work.


    Please help me to solve the problem.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: multiple pgsql databases in QT with a single QTthread

    QSqlDatabase::addDatabase have second parameter connectionName.

Similar Threads

  1. Multiple timers in single Application
    By Qt Coder in forum Qt Programming
    Replies: 47
    Last Post: 5th October 2012, 13:23
  2. Multiple open databases and MVC
    By mtnbiker66 in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2012, 00:08
  3. Multiple model to single view
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 4
    Last Post: 9th March 2012, 09:57
  4. Should I use multiple or a single model(s)?
    By Cotlone in forum Newbie
    Replies: 2
    Last Post: 7th May 2010, 03:39
  5. Multiple appearances in a single ui file
    By zgulser in forum Qt Tools
    Replies: 1
    Last Post: 5th June 2009, 19:12

Tags for this Thread

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.