| 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>Chapter 6. C# API</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="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 11 | <link rel="prev" href="java_faq.html" title="Java FAQ" /> |
| 12 | <link rel="next" href="stl.html" title="Chapter 7. Standard Template Library API" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Chapter 6. C# API</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="java_faq.html">Prev</a> </td> |
| 25 | <th width="60%" align="center"> </th> |
| 26 | <td width="20%" align="right"> <a accesskey="n" href="stl.html">Next</a></td> |
| 27 | </tr> |
| 28 | </table> |
| 29 | <hr /> |
| 30 | </div> |
| 31 | <div class="chapter" lang="en" xml:lang="en"> |
| 32 | <div class="titlepage"> |
| 33 | <div> |
| 34 | <div> |
| 35 | <h2 class="title"><a id="csharp"></a>Chapter 6. C# API</h2> |
| 36 | </div> |
| 37 | </div> |
| 38 | </div> |
| 39 | <div class="toc"> |
| 40 | <p> |
| 41 | <b>Table of Contents</b> |
| 42 | </p> |
| 43 | <dl> |
| 44 | <dt> |
| 45 | <span class="sect1"> |
| 46 | <a href="csharp.html#csharp_compat">Compatibility</a> |
| 47 | </span> |
| 48 | </dt> |
| 49 | </dl> |
| 50 | </div> |
| 51 | <p>You can use Berkeley DB in your application through the C# API. To understand the application concepts relating to Berkeley DB, see the first few chapters of this manual. |
| 52 | For a general discussion on how to build Berkeley DB applications, see the Berkeley DB Getting Started Guides of C or C++. |
| 53 | You can also review the example code of C and C++ from the examples_c and examples_cxx directories. For a description of all the classes, functions, and enumerations of Berkeley DB C# API, see the <a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/csharp/Index.html" target="_top"> |
| 54 | Berkeley DB C# API Reference Guide. |
| 55 | </a></p> |
| 56 | <p> |
| 57 | A separate Visual Studio solution is provided to build the Berkeley DB |
| 58 | C# classes, the examples, and the native support library. See |
| 59 | <a href="../installation/build_win_csharp.html#build_win_csharp.title" class="olink">Building the C# API</a> in the Berkeley DB Installation and Build Guide for more information. |
| 60 | </p> |
| 61 | <p> |
| 62 | The C# API requires .NET framework version 2.0 or above, and expects that |
| 63 | it has already been installed on your system. For the sake of |
| 64 | discussion, we assume that the Berkeley DB source is in a directory |
| 65 | called db-<span class="emphasis"><em>VERSION</em></span>; for example, you downloaded a |
| 66 | Berkeley DB archive, and you did not change the top-level directory |
| 67 | name. The files related to C# are in four subdirectories of |
| 68 | db-<span class="emphasis"><em>VERSION</em></span>: csharp (the C# source files), |
| 69 | libdb_csharp (the C++ files that provide the "glue" between C# and |
| 70 | Berkeley DB,) examples_csharp (containing all example code) and |
| 71 | test\scr037 (containing NUnit tests for the API). |
| 72 | </p> |
| 73 | <p> |
| 74 | Building the C# API produces a managed assembly |
| 75 | <code class="filename">libdb_dotnet<span class="emphasis"><em>VERSION</em></span>.dll</code>, |
| 76 | containing the API, and two native libraries: |
| 77 | <code class="filename">libdb_csharp<span class="emphasis"><em>VERSION</em></span>.dll</code> and |
| 78 | <code class="filename">libdb<span class="emphasis"><em>VERSION</em></span>.dll</code>. (For all |
| 79 | three files, <span class="emphasis"><em>VERSION</em></span> is [MAJOR][MINOR], i.e. for |
| 80 | version 4.8 the managed assembly is |
| 81 | <code class="filename">libdb_dotnet48.dll</code>.) Following the existing |
| 82 | convention, native libraries are placed in either |
| 83 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\build_windows\Win32</code>or |
| 84 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\build_windows\x64</code>, |
| 85 | depending upon the platform being targeted. In all cases, the managed |
| 86 | assembly will be placed in |
| 87 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\build_windows\AnyCPU</code>. |
| 88 | </p> |
| 89 | <p> |
| 90 | Because the C# API uses P/Invoke, for your application to use Berkeley |
| 91 | DB successfully, the .NET framework needs to be able to locate the |
| 92 | native libaries. This means the native libraries need to either be |
| 93 | copied to your application's directory, the Windows or System |
| 94 | directory, or the location of the libraries needs to be added to the |
| 95 | <code class="literal">PATH</code> environment variable. See the MSDN |
| 96 | documentation of the DllImport attribute and Dynamic-Link Library |
| 97 | Search Order for further information. |
| 98 | </p> |
| 99 | <p> |
| 100 | If you get the following exception when you run, the .NET platform probably |
| 101 | is unable to locate the native libraries: |
| 102 | </p> |
| 103 | <pre class="programlisting">System.TypeInitializationException</pre> |
| 104 | <p> |
| 105 | To ensure that everything is running correctly, you may want to try a |
| 106 | simple test from the example programs in the |
| 107 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\examples_csharp</code> |
| 108 | directory. |
| 109 | </p> |
| 110 | <p> |
| 111 | For example, the ex_access sample program will prompt for text input |
| 112 | lines, which are then stored in a Btree database named |
| 113 | <code class="filename">access.db</code>. It is designed to be run from either |
| 114 | the |
| 115 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\build_windows\Debug</code> |
| 116 | or |
| 117 | <code class="filename">db-<span class="emphasis"><em>VERSION</em></span>\build_windows\Release</code> |
| 118 | directory. Try giving it a few lines of input text and then a blank |
| 119 | line. Before it exits, you should see a list of the lines you entered |
| 120 | display with data items. This is a simple check to make sure the |
| 121 | fundamental configuration is working correctly. |
| 122 | </p> |
| 123 | <div class="sect1" lang="en" xml:lang="en"> |
| 124 | <div class="titlepage"> |
| 125 | <div> |
| 126 | <div> |
| 127 | <h2 class="title" style="clear: both"><a id="csharp_compat"></a>Compatibility</h2> |
| 128 | </div> |
| 129 | </div> |
| 130 | </div> |
| 131 | <p> |
| 132 | The Berkeley DB C# API has been tested with the Microsoft .NET Framework versions 2.0, 3.0, 3.5, and 4.0. |
| 133 | </p> |
| 134 | </div> |
| 135 | </div> |
| 136 | <div class="navfooter"> |
| 137 | <hr /> |
| 138 | <table width="100%" summary="Navigation footer"> |
| 139 | <tr> |
| 140 | <td width="40%" align="left"><a accesskey="p" href="java_faq.html">Prev</a> </td> |
| 141 | <td width="20%" align="center"> </td> |
| 142 | <td width="40%" align="right"> <a accesskey="n" href="stl.html">Next</a></td> |
| 143 | </tr> |
| 144 | <tr> |
| 145 | <td width="40%" align="left" valign="top">Java FAQ </td> |
| 146 | <td width="20%" align="center"> |
| 147 | <a accesskey="h" href="index.html">Home</a> |
| 148 | </td> |
| 149 | <td width="40%" align="right" valign="top"> Chapter 7. Standard Template Library API</td> |
| 150 | </tr> |
| 151 | </table> |
| 152 | </div> |
| 153 | </body> |
| 154 | </html> |