Database Connection Problem



  • I am working in a database project using MYSQL with Qt. My application is connecting with database, If Qt and MySQL are in the same PC. But If I run my application from another PC and I am trying to connect to the database through ethernet, It is not connecting. This is my connection code:

    @ m_sqlDB = QSqlDatabase::addDatabase("QODBC");
    m_sqlDB.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};Server=10.3.3.102;DATABASE=ADTL;");
    m_sqlDB.setUserName("root");
    m_sqlDB.setPassword("abcdef");

    if (!m_sqlDB.open()) {
        QMessageBox::critical(0, qApp->tr("Cannot open database"),
            qApp->tr("Unable to establish a database connection.\n"
                     "Click Cancel to exit."), QMessageBox::Cancel);
        return ;
    }@
    

    Kindly guide me, what i am missing.

    Thanks & Regards
    Bagavathikumar


  • Lifetime Qt Champion

    Hi,

    Did you deploy all needed dlls with your application on the other computer ?



  • My application is working correctly, but the problem is in when i am calling the 'Open' API (QSqlDatabase). Basically my setup is like this:

    I have a two computers and both are connected to local intranet.

    Computer 1: I installed MySQL 5.5, MySQL ODBC 5.1 Driver and Qt 5.2. When I execute my code in this computer, The Application is connecting to the database without any problem.

    Computer 2: I installed only Qt 5.2. When I execute my code in this computer, the database Open API gets failed. Because Database is resides in Computer 1 and I am using IP address of Computer 1 in my code.

    Now I want to know whether I need to install ODBC driver in the Computer 2? or anything else is required to connect the remote database using ODBC method.



  • Finally my application is connecting to the database, after install the MySQL ODBC 5.1 Driver in the Computer 2.

    But How do I ensure the required ODBC drivers are installed in the computer, when I deploy the application. Or what are the dll files required to include in my installation for ODBC?

    Thanks & Regards
    Bagavathikumar



  • You mean the sql driver?


  • Lifetime Qt Champion

    Also, did you setup your database to allow connection from other computers ?



  • bq. You mean the sql driver?

    Yes

    bq. Also, did you setup your database to allow connection from other computers ?

    I've not done any setup. I installed the MYSQL 5.5 with MySQL ODBC 5.1 Driver in computer 1 and only MySQL ODBC 5.1 Driver in Computer 2.


  • Lifetime Qt Champion

    Then check first that your database accepts connections from an external computer


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.