Best way to get connection string for IBATIS.NET from web.config

I have a web application in which I have a requirement to encrypt and store the connection string in the web.config file.

What is the best way to get this and use this connection string with IBATIS.NET instead of saving the connection string in SqlMap.config?

+3
source share
2 answers

The last three posts in this discussion thread discuss what you want.

Essentially, you overwrite the iBATIS connection string from the configuration file before calling Configure ().

For example, in your SqlMap.config:


   <database>
      <provider name="sqlServer2005" />
      <dataSource name="TheDB" connectionString="${connectionString}"/>
   </database>

And in your code where you are setting up the constructor, something like:


DomSqlMapBuilder builder;
string connection;
NameValueCollection properties;

connection = AccessTheEncryptedStringHere();

// Put the string in collection to pass to the iBATIS configurator
properties = new NameValueCollection();
properties.Add("connectionString", connection);

// Build the iBATIS configurator
builder = new DomSqlMapBuilder();
builder.Properties = properties;
builder.Configure("SqlMap.config");

+4

? web.config -

. -- - omni_dbConnectionString

string connectionString = ConfigurationManager.ConnectionStrings [ "myProtectedConfigProvider" ]. ProviderName;

string connectionString = ConfigurationManager.ConnectionStrings [ "omni_dbConnectionString" ]. ConnectionString;

0

All Articles