Avatar of AidenA
AidenA
 asked on

ASP.NET ensure website is using a particular configuration string when published to server

Hi,

As the title suggests, I am using a different database during development. It's easy enough to ensure that I am using the development database during development because I can do a simple debug.assert to ensure I am using the correct connection string.

However, I can't quite think how I would ensure that when the site is being published, or on the server, that a check is made to ensure the production version is using the production database.

Can anyone provide info on that?

Thanks, Aiden
ASP.NETVisual Basic.NET.NET Programming

Avatar of undefined
Last Comment
AidenA

8/22/2022 - Mon
b_levitt

You have a couple of options.  One is to use config transforms:
http://msdn.microsoft.com/en-us/library/dd465326.aspx

Depending on your build configuration, different transforms are applied when you publish your site.  I do use this for everything BUT connection strings, since in my case I use source control and I do not want production passwords checked in for all to see inside of source control.

Another option is to take advantage of configuration inheritance and define your connection string above the site level in machine level web.config (%windir%\Microsoft.Net\Framework\<version>\Config).  That way your connection would be machine specific and wouldn't move with your deployed code.
http://msdn.microsoft.com/en-us/library/ms178685.aspx
gopaltayde

AidenA

ASKER
Hi, thanks for that.

source control? haven't heard of that before, so it looks like it means you can change the production environment from your development environment, or is it more about collaboration with other programming teams?

Anyway, I guess first things first, the config transforms sounds perfect, but is that just for .NET 4.0 or can it be used in .NET 2.0 do you know? Otherwise yeah, the second option would work also... haven't worked with machine config before but I assume it's not difficult
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
b_levitt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
AidenA

ASKER
ok thanks for that... that's enough to get me sorted out

Aiden