Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Open MYSQL Database with connectionName
Forum Updated to NodeBB v4.3 + New Features

Open MYSQL Database with connectionName

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 6.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    That's not a Qt problem there. You otherName user doesn't have access to the database you want to get.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • H Offline
      H Offline
      helenebro
      wrote on last edited by
      #7

      Yes but "OtherName" isn't the name that I have set with dbMyApp.setUserName("userName");

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #8

        How did you setup the databases ?

        Out of curiosity, why two different databases for your application ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • H Offline
          H Offline
          helenebro
          wrote on last edited by
          #9

          What do you mean by saying "setup" ?

          MyApp

          MyApp::MyApp(QQmlContext *ctx, QObject *parent) : QObject( parent)
          {
              QSqlDatabase::addDatabase("QMYSQL3", "myapp");
              QSqlDatabase::addDatabase("QMYSQL3", "myclass");
              MyClass *myClass = new MyClass();
              ctx->setContextProperty("myClass", myClass);
              dbMyApp = QSqlDatabase::database("myapp");
              dbMyApp.setHostName("localhost");
              dbMyApp.setUserName("root");
              dbMyApp.setPassword("mySQL:r00t");
              dbMyApp.setDatabaseName("cube_application");
              getDataMyApp();
          }
          

          MyClass

          MyClass::MyClass(QObject *parent) : QObject(parent)
          {
              dbMyClass = QSqlDatabase::database("myclass");
              dbMyClass.setHostName("localhost");
              dbMyClass.setUserName("root");
              dbMyClass.setPassword("mySQL:r00t");
              dbMyClass.setDatabaseName("catalogue_4mod");
              getDataMyClass();
          }
          

          I have two databases because data have no relationship. My application contains several "mini application".

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #10

            I meant server side setup.

            But again why multiple databases ? You can have your unrelated tables in only one database. They don't need to have any relation between them.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • H Offline
              H Offline
              helenebro
              wrote on last edited by
              #11

              My database is only on localhost and create by command line.
              Indeed the two database can be merged, I find it more clear like this (It is maybe a mistake)

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #12

                Do you mean you find it more clear to connect your application to two different databases ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  helenebro
                  wrote on last edited by
                  #13

                  Yes, because my application is the merge of different application which has a data on database

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    That I understood, but still, deploying several databases for one application sounds like an overkill.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • H Offline
                      H Offline
                      helenebro
                      wrote on last edited by helenebro
                      #15

                      Ok, I will merge my two databases

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lqsa
                        wrote on last edited by lqsa
                        #16

                        In my app, the 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.
                        

                        solves when pass the database on QSqlQuery constructor.

                        In your case could be something like QSqlQuery(dbMyClass) for querys on MyClass and QSqlQuery(dbApp) for querys on MyApp.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved