Library Version 12.1.6.0

Dbc::close()
Prev | Chapter 3. The Dbc Handle | Next

## Dbc::close()

    #include <db_cxx.h>

    int
    Dbc::close(void);

The `Dbc::close()` method discards the cursor.

It is possible for the `Dbc::close()` method to return DB_LOCK_DEADLOCK, signaling that any enclosing transaction should be aborted. If the application is already intending to abort the transaction, this error should be ignored, and the application should proceed.

After the `Dbc::close()` method has been called, regardless of its return value, you can not use the cursor handle again.

It is not required to close the cursor explicitly before closing the database handle or the transaction handle that owns this cursor because, closing a database handle or a transaction handle closes those open cursors.

However, it is recommended that you always close all cursor handles immediately after their use to promote concurrency and to release resources such as page locks.

The `Dbc::close()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Errors

The `Dbc::close()` method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

#### DbDeadlockException or DB_LOCK_DEADLOCK

A transactional database environment operation was selected to resolve a deadlock.

DbDeadlockException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, `DB_LOCK_DEADLOCK` is returned.

#### DbLockNotGrantedException or DB_LOCK_NOTGRANTED

A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time.

You attempted to open a database handle that is configured for no waiting exclusive locking, but the exclusive lock could not be immediately obtained. See Db::set_lk_exclusive() for more information.

DbLockNotGrantedException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, `DB_LOCK_NOTGRANTED` is returned.

#### EINVAL

If the cursor is already closed; or if an invalid flag value or parameter was specified.

### Class

Dbc

### See Also

Database Cursors and Related Methods

Prev | Up | Next
Db::cursor() | Home | Dbc::cmp()