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