Results 1 to 3 of 3

Thread: [solved] Connectin Two DB at the same time

  1. #1
    Join Date
    May 2014
    Posts
    8
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default [solved] Connectin Two DB at the same time

    I'm tryng to connect a MySql database, select some data from different tables and then copy them on a PostgreSql database.
    I'm doing the connection operation but i've some problem.
    I'm connecting both db at the same time an i'm getting this errors:

    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.

    My mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QtSql>
    6. #include <QtCore>
    7. #include <QtGui>
    8. #include <QDebug>
    9.  
    10. namespace Ui {
    11. class MainWindow;
    12. }
    13.  
    14. class MainWindow : public QMainWindow
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit MainWindow(QWidget *parent = 0);
    20. ~MainWindow();
    21.  
    22. private slots:
    23. void on_pushButton_clicked();
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    my mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::on_pushButton_clicked()
    17. {
    18. db=QSqlDatabase::addDatabase("QMYSQL");
    19. db.setHostName("localhost");
    20. db.setDatabaseName("vtigercrm540a");
    21. db.setUserName("root");
    22. db.setPassword("1234");
    23. db.open();
    24.  
    25. db2=QSqlDatabase::addDatabase("QPSQL");
    26. db2.setHostName("localhost");
    27. db2.setDatabaseName("prova");
    28. db2.setUserName("postgres");
    29. db2.setPassword("1234");
    30. db2.open();
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 

    TIA
    Last edited by gustavospammo; 8th May 2014 at 17:01.
    Windows 8.1 64 bit
    Qt Creator 3.0.1
    Based on Qt 5.2.1 (MSVC 2010, 32 bit)
    mingw48_32
    Postgresql 9.3 32bit
    xampp 1.7.7 vc9 32bit

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connectin Two DB at the same time

    Pass distinct connection names to the two addDatabase() calls.

    Cheers,
    _

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

    gustavospammo (8th May 2014)

  4. #3
    Join Date
    May 2014
    Posts
    8
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Connectin Two DB at the same time

    Solved
    I've modiefied
    db=QSqlDatabase::addDatabase("QMYSQL", "connection1");
    db2=QSqlDatabase::addDatabase("QPSQL", "connection2");
    Windows 8.1 64 bit
    Qt Creator 3.0.1
    Based on Qt 5.2.1 (MSVC 2010, 32 bit)
    mingw48_32
    Postgresql 9.3 32bit
    xampp 1.7.7 vc9 32bit

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 03:25
  2. Replies: 6
    Last Post: 18th August 2010, 13:52
  3. Replies: 1
    Last Post: 25th June 2010, 19:31
  4. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 10:10

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.