Hi,
I have 2 connectionstrings in the web.config file in my website. It has a xsd file of handling all the database calls etc.
I wonder how do I switch the connectionstring used in the xsd file in code-behind?
Basically, my web.config will have a setting indicates whether website is test mode or live mode in appSetting region:
<add key="mode" value="">
So:
<add key="mode" value="test"> <!--is testing mode-->
<add key="mode" value="live"> <!--is live mode-->
depend on this than the whole site is using the appropriate connection string, sample code:
public static string ConnectionString
{
get
{
if (IsTesting)
{
return ConfigurationManager.ConnectionStrings["Test"].ToString();
}
else
{
return ConfigurationManager.ConnectionStrings["Live"].ToString();
}
}
}
But how to you set the xsd file following this rule?
Thanks in advance.
Hi,
As far as I can see, we don't use .xsd file to switch this. From your code, I can see that your ConfigurationManager is reading from web.config for the targeted connectionstring directly. So the only thing we need to do is to set the IsTesting flag. I think you can add a new key in Web.Config to indicate if the testing mode is true or false.
0 comments:
Post a Comment