<h2class="title"style="clear: both"><aid="transapp_env_open"></a>Opening the environment</h2>
</div>
</div>
</div>
<p>
Creating transaction-protected applications using the Berkeley DB
library is quite easy. Applications first use <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a> to initialize
the database environment. Transaction-protected applications normally
require all four Berkeley DB subsystems, so the <ahref="../api_reference/C/envopen.html#envopen_DB_INIT_MPOOL"class="olink">DB_INIT_MPOOL</a>,
<ahref="../api_reference/C/envopen.html#envopen_DB_INIT_LOCK"class="olink">DB_INIT_LOCK</a>, <ahref="../api_reference/C/envopen.html#envopen_DB_INIT_LOG"class="olink">DB_INIT_LOG</a>, and <ahref="../api_reference/C/envopen.html#envopen_DB_INIT_TXN"class="olink">DB_INIT_TXN</a> flags should be
specified.
</p>
<p>
Once the application has called <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a>, it opens its databases
within the environment. Once the databases are opened, the application
makes changes to the databases inside of transactions. Each set of
changes that entails a unit of work should be surrounded by the
appropriate <ahref="../api_reference/C/txnbegin.html"class="olink">DB_ENV->txn_begin()</a>, <ahref="../api_reference/C/txncommit.html"class="olink">DB_TXN->commit()</a> and <ahref="../api_reference/C/txnabort.html"class="olink">DB_TXN->abort()</a> calls. The Berkeley
DB access methods will make the appropriate calls into the Lock, Log
and Memory Pool subsystems in order to guarantee transaction semantics.
When the application is ready to exit, all outstanding transactions
should have been committed or aborted.
</p>
<p>
Databases accessed by a transaction must not be closed during the
transaction. Once all outstanding transactions are finished, all open
Berkeley DB files should be closed. When the Berkeley DB database
files have been closed, the environment should be closed by calling