Installation and deployment Questions on installation, system configuration and deployment to the live server.
Version 6.x > Installation and deployment > ConnectionString Name Issue View modes: 
User avatar
Member
Member
kentico-bytix - 11/13/2012 1:19:33 AM
   
ConnectionString Name Issue
Dear Developers...

I've got a question for you:

We have multiple Kentico Installations in different versions. We are currently building our new Dev-Staging-Live Environment.

Now for usability reasons we want the connection strings outsourced in a new file called ConnectionStrings laying in the following folder:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG
This file will be referenced by the Machine.config.

So now to my question... how can i solve the issue with the same names? All Connection strings are called CMSConnectionString....

How can i rename them in the CMS without have to reinstall. Or is there a possibility to refer a ConnectionString. E.g.:

This is an example ConnectionString:
<add name="CMSConnectionString" connectionString="Persist Security Info=False;database=DATABASE;server=SERVER;user id=XXX;password=YYY;Current Language=English;Connection Timeout=240;" />

Is there a possibility to do something like this:
<add name="CMSConnectionString" ReferrConnectionString="XXXConnectionString1"/>

We need a solution for this... Is there an easy ability to change the connection string in the CMS?

Thanks for your help...

Regards
Patrick

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/15/2012 6:54:01 AM
   
RE:ConnectionString Name Issue
Hi,

I have discussed this issue with our developer and he has suggested the following way:

1) Define module loader (\App_Code\Samples\Modules\) and override the method PreInit instead of Init

2) In the PreInit method load your file with connection strings, and using
SettingsHelper.ConnectionStrings["CMSConnectionString"] = connString;
set a new connection string dynamically

3) Maybe it will be also necessary to change property SqlHelperClass.ConnectionString manually

Unfortunately, this should work only from v7.

Best regards,
Martin Danko

User avatar
Member
Member
kentico-bytix - 11/15/2012 7:18:46 AM
   
RE:ConnectionString Name Issue
Dear Martin...

Thanks for that advice... i'm going to try it also..

in the meantime i talked with Radek... and this is the result:
Dear Radek...

First of all thanks for your Help/Ideas...

As i had to accept that there was no way to change the Connection Strings name, Radek pointet me out a good iead for my problem.

This was my question to Radek:

Well our goal is the following:

We are starting to use TFS…

Imagine you have Dev-Staging-Live environment.

If someone is working on dev and has settings to do in web.config, then he does the changes he has to do and checks it in.

On the day before GoLive we Merge all the changesets that are defined to go live to Staging. And here ist he problem… if in the Changeset the Web.Config file is, then the ConnectionString from the Development environment would also get merged…

If we could outsource them by a name (which i think would not be a big problem in the installation phase of the project), then we could create a DevConnectionsStrings.config a StagingConnectionStrings.config and a LiveConnectionStrings.config file and deploy them on the servers… and nobody would have to bother about connection strings anymore…

And his answer made me rethink:

Radeks Partial Answer:
In this case, you could use inheriting the web.config files in a way, that the web.config will be defined in web site’s root and particular applications will inherit it, like:

/inetpub/wwwroot/web.config with connectionString
/inetpub/wwwroot/app/web.config – without connectionString and /clear element.

And my Final Solution will be that i will Create a ConnectionFile for each CMS.

As en example:
My CMS Customer is Called Foo.

I am going to create a FooConnectionString.config File laying in the folder:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

containing:
<connectionStrings>
<add name="CMSConnectionString" connectionString="Persist Security Info=False;database=Foo;server=SERVER;user id=USER;password=PASSWORd;Current Language=English;Connection Timeout=240;" />
</connectionStrings>

And in the Web.Config i just set the
<ConnectionStrings configSource ="C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\FooConnectionString.config" />

And the magic is if on the Staging and Prod servers the same files are laying then no one has to bother about connection strings on the desired environments anymore...

Hope i could help anyone...

Regards
Patrick

But thanks anyway for your approach...

i'll let you know if it also works...

Regards
Patrick

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/15/2012 7:30:44 AM
   
RE:ConnectionString Name Issue
Hi Patrick,

Yes, I've already seen the second thread with Radek.

Just 2 notes from me:
1. Please don't post the same question into multiple threads
2. You don't need to quote the whole post, just click reply... For better readability :)

Thank you.

Best regards,
Martin Danko