views:

782

answers:

2

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?

+3  A: 

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");

Nicholas Piasecki
thanks for that! I always find information for iBATIS.NET difficult even using google
Jon Cahill
I've been using it for for 2 years now and just stumbled across a feature that I hadn't been aware of. The mailing lists generally are one of the best documentation resources. And next to that, the source itself. Good framework, but yeah, the docs are sparse. Good luck!
Nicholas Piasecki
iBATIS.NET is almost a secret on the web ;-) Thanks for the info.
John Paul Jones
@Nicholas: Me too. Now that I've found this question on SO, I'm one step closer to completing my personal collection of iBATIS.NET tips and tricks. Maybe someday I'll share them :)
Cory Larson
A: 

Are you looking out for this? retrieving the encrypted connectionstring from web.config--

You can try the foll. code-- name of the connection string is omni_dbConnectionString

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

or

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