Change Connectionstring name

Jul 17, 2008 at 12:49 PM
Hi,

is it possible to set the connectionStrings name in runtime?
I'd like to do this to support a test and live website with the same deployment.
I have a N2CMS and N2CMSDEMO connectionstring for instance...

Martijn
Jul 17, 2008 at 1:13 PM
Yes, take a look at Web Deployment Projects.

If you are using VS 2008, right click on your web application project and click "Add Web Deployment Project...". Then, you can specify a custom connectionStrings file for every build (and thus creat a debug, release, test, beta, whatever release and it's custom connection strings and application settings).
Coordinator
Jul 17, 2008 at 2:13 PM
Edited Jul 17, 2008 at 2:13 PM
A possible alternative would be programmatically changing the configuration file (requires write permissions to the configuration file and app restart):

            Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~");

            DatabaseSection db= (DatabaseSection)cfg.GetSection("n2/database");
            db.ConnectionStringName= "N2CMSDEMO";

            cfg.Save();
Jul 17, 2008 at 3:07 PM


Tischnoetentoet wrote:
Yes, take a look at Web Deployment Projects.

If you are using VS 2008, right click on your web application project and click "Add Web Deployment Project...". Then, you can specify a custom connectionStrings file for every build (and thus creat a debug, release, test, beta, whatever release and it's custom connection strings and application settings).

Thanks, but I want to use the same deployment. I was already doing this for development and production servers.
I want a live and demo server hosted.
Jul 17, 2008 at 3:08 PM


libardo wrote:
A possible alternative would be programmatically changing the configuration file (requires write permissions to the configuration file and app restart):

            Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~");

            DatabaseSection db= (DatabaseSection)cfg.GetSection("n2/database");
            db.ConnectionStringName= "N2CMSDEMO";

            cfg.Save();


Hmm, I did find that one, hoped there was something else.
I'll give it a try, thanks!
Coordinator
Jul 17, 2008 at 3:56 PM
A more complex solution would be creating and configuring a custom ISessionProvider that returns nhibernate sessions from different session factories.