Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void QSqlDatabase::setDatabaseName ( const QString name  ) 

Sets the connection's name to name. This must be done before the connection is opened or it has no effect; (or you can close() the connection, call this function and open() the connection again). The name is database-specific.

For the QOCI (Oracle) driver, the database name is the TNS Service Name.

For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.

For example, Microsoft Access users can use the following connection string to open an .mdb file directly, instead of having to create a DSN entry in the ODBC manager:

    db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
    if (db.open()) {
        // success!

There is no default value.

See also:
databaseName() setUserName() setPassword() setHostName() setPort() setConnectOptions() open()

Definition at line 958 of file qsqldatabase.cpp.

References isValid().

    if (isValid())
        d->dbname = name;

Generated by  Doxygen 1.6.0   Back to index