EPiServer connection string at runtimeA customer asked if it was possible to set the database connection string programmatically in an EPiServer site. In the customer's specific example they wanted to use a configuration database rather than store any configuration in a .config file.

This can be achieved by creating a custom IDatabaseFactory implementation that allows you to set the connection string programmatically:

Then letting EPiServer know that this should be used in place of the default implementation using an initialization module:

It should be noted that IDatabaseFactory that "IDatabaseFactory supports the EPiServer infrastructure and is not intended to be used directly from your code." so be careful!

I've not tested this beyond a basic smoke test so please do let me know if you find any problems with the implementation...


Recommendations for you