<html dir="LTR" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:MSHelp="http://msdn.microsoft.com/mshelp" xmlns:tool="http://www.microsoft.com/tooltip" xmlns:ndoc="urn:ndoc-preprocess">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" />
    <title>DbProviderFactory Support</title>
    <link rel="stylesheet" type="text/css" href="ndoc.css"> </link>
    <link rel="stylesheet" type="text/css" href="user.css"> </link>
    <script type="text/javascript" src="ndoc.js"> </script>
  </head>
  <body style="display: none;">
    <input type="hidden" id="userDataCache" class="userDataStyle" />
    <input type="hidden" id="hiddenScrollOffset" />
    <img id="dropDownImage" style="display:none; height:0; width:0;" src="drpdown.gif" />
    <img id="dropDownHoverImage" style="display:none; height:0; width:0;" src="drpdown_orange.gif" />
    <img id="collapseImage" style="display:none; height:0; width:0;" src="collapse.gif" />
    <img id="expandImage" style="display:none; height:0; width:0;" src="exp.gif" />
    <img id="collapseAllImage" style="display:none; height:0; width:0;" src="collall.gif" />
    <img id="expandAllImage" style="display:none; height:0; width:0;" src="expall.gif" />
    <img id="copyImage" style="display:none; height:0; width:0;" src="copycode.gif" />
    <img id="copyHoverImage" style="display:none; height:0; width:0;" src="copycodeHighlight.gif" />
    <div id="header">
      <table width="100%" id="topTable">
        <tr id="headerTableRow1">
          <td align="left">
            <span id="runningHeaderText">DbProviderFactory Support</span>
          </td>
        </tr>
        <tr id="headerTableRow2">
          <td align="left">
            <span id="nsrTitle">SQLite.NET Class Library Documentation</span>
          </td>
        </tr>
        <tr id="headerTableRow3" style="display:none">
          <td>
            <a id="seeAlsoSectionLink" href="#seeAlsoToggle" onclick="OpenSection(seeAlsoToggle)">See Also</a>
            <a id="exampleSectionLink" href="#codeExampleToggle" onclick="OpenSection(codeExampleToggle)">Example</a>
          </td>
        </tr>
     </table>
      <table width="100%" id="bottomTable" cellspacing="0" cellpadding="0" style="display:none">
        <tr>
          <td>
            <span onclick="ExpandCollapseAll(toggleAllImage)" style="cursor:default;" onkeypress="ExpandCollapseAll_CheckKey(toggleAllImage)" tabindex="0">
              <img ID="toggleAllImage" class="toggleAll" src="collall.gif" />
              <label id="collapseAllLabel" for="toggleAllImage" style="display: none;">
							Collapse All
						</label>
              <label id="expandAllLabel" for="toggleAllImage" style="display: none;">
							Expand All
						</label>
            </span>
          </td>
        </tr>
      </table>
    </div>
    <div id="mainSection">
    <div id="mainBody">
      <h1 class="heading">DbProviderFactories and You</h1>
      <p>One of the great new features of ADO.NET 2.0 is the use of reflection as a 
        means of instantiating database providers programmatically. The information 
        .NET uses to enumerate the available data providers in the system is relatively 
        simple. It merely looks in the machine.config and in your own app.config file for some XML data to tell it what providers are 
        installed and what assemblies those providers are in.
      </p>
      <h4>
        Scenario 1:&nbsp; Version Independent (does not use the Global Assembly Cache)</h4>
      <p>
        This method allows you to drop any new version of the System.Data.SQLite.DLL into
        your application's folder and use it without any code modifications or recompiling.&nbsp;
        Add the following code to your app.config file:</p>
      <div class="syntax">
        <PRE>&lt;configuration&gt;
  &lt;system.data&gt;
    &lt;DbProviderFactories&gt;
      &lt;remove invariant="System.Data.SQLite"/&gt;
      &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite"
           description=".Net Framework Data Provider for SQLite"<br />           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /&gt;
    &lt;/DbProviderFactories&gt;
  &lt;/system.data&gt;
&lt;/configuration&gt;
</PRE>
      </div>
      <h4>
        Scenario 2:&nbsp; Version Dependent, using either the DLL located in the same folder
        as the application or the Global Assembly Cache</h4>
      <p>
        This method expands on the above XML to provide the version number and key token
        of the SQLite DLL so it can be found either in the same folder as the application
        or looked up in the GAC.&nbsp; The downside to this method is that DbProviderFactories
        will use this version information to only load the version specified.&nbsp; This
        means if you update the DLL, you must also update this XML.</p>
      <div class="syntax">
        <PRE>
&lt;configuration&gt;
  &lt;system.data&gt;
    &lt;DbProviderFactories&gt;
      &lt;remove invariant="System.Data.SQLite"/&gt;
      &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" 
           description=".Net Framework Data Provider for SQLite"
           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
                 Version=1.0.49.0, Culture=neutral,
                 PublicKeyToken=db937bc2d44ff139"/&gt;
    &lt;/DbProviderFactories&gt;
  &lt;/system.data&gt;
&lt;/configuration&gt;
</pre>
      </div>
      <p>
        The following C# code demonstrates 
        instantiating SQLite through DbProviderFactories:</p>
      <div class="syntax"><pre>      DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
      using (DbConnection cnn = fact.CreateConnection())
      {
        cnn.ConnectionString = "Data Source=test.db3";
        cnn.Open();
      }</pre>
      </div>
      <hr>
      <div id="footer">
        <p>
          <a href="mailto:robert@blackcastlesoft.com?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Factory%20Support">
            Send comments on this topic.</a>
        </p>
        <p>
        </p>
      </div>
    </div>
    </div>
  </body>
</html>
