Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Both SqlConnection and SqlCEConnection extend System.Data.Common.DbConnection, so declare "blah" as DbConnection, and you will able to use the same methods and properties.</p> <p>To actually create the correct connection type, use the System.Data.Common.DbProviderFactories and System.Data.Common.DbProviderFactory classes. For example:</p> <pre><code>DbProviderFactory providerFactory = DbProviderFactories.GetFactory("The Provider Name"); using (DbConnection connection = providerFactory.CreateConnection()) { connection.ConnectionString = "The Connection String"; connection.Open(); // Use the "connection" object here } </code></pre> <p>For "The Provider Name", you would put in either "System.Data.SqlClient" or "System.Data.SqlServerCe" depending on the database type. And then for "The Connection String", you would put in the correct connection string for the provider type.</p> <p><strong>EDIT:</strong> this technique works well with your App.config file and the System.Configuration.ConfigurationManager class. For example, if your App.config file looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;configuration&gt; &lt;connectionStrings&gt; &lt;add name="TheConnectionString" providerName="System.Data.SqlClient" connectionString="Blah Blah Blah" /&gt; &lt;/connectionStrings&gt; &lt;/configuration&gt; </code></pre> <p>Then you can access these configuration settings like this:</p> <pre><code>DbProviderFactory providerFactory = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings["TheConnectionString"].ProviderName); using (DbConnection connection = providerFactory.CreateConnection()) { connection.ConnectionString = ConfigurationManager.ConnectionStrings["TheConnectionString"].ConnectionString; connection.Open(); // Use the "connection" object here } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload