Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 375
Jon Cahill Avatar asked Dec 04 '25 08:12

Jon Cahill


1 Answers

The last three messages of this discussion thread discuss what you want.

Essentially, you're overwriting the connection string iBATIS loads from the config file before your call to Configure().

For example, in your SqlMap.config:


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

And in your code where you configure the builder, 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");

like image 107
Nicholas Piasecki Avatar answered Dec 07 '25 15:12

Nicholas Piasecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!