You create Web-based client applications. You are creating an application that must access different databases depending on whether the application is in demonstration, production, or test mode. The mode is stored in an environment variable. The configuration file contains the following settings.
<connectionStrings>
<add name = “ProdDB” connectionString = “Data Source = server; Initial Catalog = ProdDatabase; Integrated_Security = true” providerName = “System.Data.SqlClient” /> <add name = “DemoDB” connectionString = “Data Source = server; Initial Catalog = DemoDatabase; Integrated_Security = true” providerName = “System.Data.SqlClient” /> <add name = “TestDB” connectionString = “Data Source = server; Initial Catalog = TestDatabase; Integrated_Security = true”
providerName = “System.Data.SqlClient” />
</connectionStrings>
You need to ensure that changing the mode will not require you to change the configuration file. Which code segment should you use?
A.
public string GetConnectionString() {
#if PROD
return WebConfigurationManager.ConnectionStrings[“ProdDB”].
ConnectionString;
#elseif DEMO
return WebConfigurationManager.ConnectionStrings[“DemoDB”].
ConnectionString;
#else
return WebConfigurationManager.ConnectionStrings[“TestDB”].
ConnectionString;
#endif
}
B.
public string GetConnectionString() {
return WebConfigurationManager.ConnectionStrings[
Environment.GetEnvironmentVariable(“WebAppModeDB”)].
ConnectionString;
}
C.
public string GetConnectionString() {
return ConfigurationSettings.AppSettings[
Environment.GetEnvironmentVariable(“WebAppModeDB”)];
}
D.
public string GetConnectionString() {
#if PROD
return ConfigurationSettings.AppSettings[“ProdDB”];
#elseif DEMO
return ConfigurationSettings.AppSettings[“DemoDB”];
#else
return ConfigurationSettings.AppSettings[“TestDB”];
#endif
}
E.
public string GetConnectionString() {
return WebConfigurationManager.ConnectionStrings[“Database”].
ConnectionString;
}