warning remove database

warning remove database

Asked on January 10, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    warning  the remove database:

    The  m_db  handle the hint to the database  to connect().

    They  altered the  m_db by using a default constructed QSqlDatabase:

    void database::close()
    {
        QString connection;
        connection = m_db.connectionName();
        m_db.close();
        m_db = QSqlDatabase();
        m_db.removeDatabase(connection);
    }
    
    Answered on January 10, 2019.
    Add Comment

    The below given code is initialized:

    void database::close()
    {
        QString connection;
        connection = m_db.connectionName();
        m_db = QSQlDatabase();
        //m_db.close();
        m_db.removeDatabase(connection);
    }
    
    Answered on January 10, 2019.
    Add Comment

    By adding an additional scope in the same device:

    QString connectionName;
    bool ok = false;
     
    {
        QSqlDatabase db = QSqlDatabase::addDatabase(databaseType);
        connectionName = db.connectionName();
        db.setHostName(hostname);
        db.setDatabaseName(databaseName);
        db.setUserName(userName);
        db.setPassword(password);
        ok = db.open();
        db.close();
    }
     
    QSqlDatabase::removeDatabase(connectionName);
    return ok;
    
    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.