1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Closing Databases</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="DB.html" title="Chapter��2.��Databases" /> 11 <link rel="prev" href="DB.html" title="Chapter��2.��Databases" /> 12 <link rel="next" href="DBOpenFlags.html" title="Database Open Flags" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Closing Databases</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="DB.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.��Databases</th> 23 <td width="20%" align="right">��<a accesskey="n" href="DBOpenFlags.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="coredbclose"></a>Closing Databases</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 Once you are done using the database, you must close it. You use the 38 <code class="methodname">DB->close()</code> 39 40 method to do this. 41 </p> 42 <p> 43 Closing a database causes it to become unusable until it is opened 44 again. Note that you should make sure that any open cursors are closed 45 before closing your database. Active cursors during a database 46 close can cause unexpected results, especially if any of those cursors are 47 writing to the database. You should always make sure that all your 48 database accesses have completed before closing your database. 49 </p> 50 <p> 51 Cursors are described in <a class="xref" href="Cursors.html" title="Chapter��4.��Using Cursors">Using Cursors</a> later in this manual. 52 </p> 53 <p> 54 Be aware that when you close the last open handle 55 for a database, then by default its cache is flushed to disk. 56 This means that any information that has 57 been modified in the cache is guaranteed to be written to disk when the 58 last handle is closed. You can manually perform this operation using 59 the 60 <code class="methodname">DB->sync()</code> 61 62 63 method, but for normal shutdown operations it is not necessary. 64 For more information about syncing your cache, see 65 <a class="xref" href="usingDbt.html#datapersist" title="Data Persistence">Data Persistence</a>. 66 </p> 67 <p>The following code fragment illustrates a database close:</p> 68 <a id="c_db2"></a> 69 <pre class="programlisting">#include <db.h> 70... 71DB *dbp; /* DB struct handle */ 72... 73 74/* 75 * Database open and access operations 76 * happen here. 77 */ 78 79... 80 81/* When we're done with the database, close it. */ 82if (dbp != NULL) 83 dbp->close(dbp, 0); </pre> 84 </div> 85 <div class="navfooter"> 86 <hr /> 87 <table width="100%" summary="Navigation footer"> 88 <tr> 89 <td width="40%" align="left"><a accesskey="p" href="DB.html">Prev</a>��</td> 90 <td width="20%" align="center"> 91 <a accesskey="u" href="DB.html">Up</a> 92 </td> 93 <td width="40%" align="right">��<a accesskey="n" href="DBOpenFlags.html">Next</a></td> 94 </tr> 95 <tr> 96 <td width="40%" align="left" valign="top">Chapter��2.��Databases��</td> 97 <td width="20%" align="center"> 98 <a accesskey="h" href="index.html">Home</a> 99 </td> 100 <td width="40%" align="right" valign="top">��Database Open Flags</td> 101 </tr> 102 </table> 103 </div> 104 </body> 105</html> 106