Trying to read the database name but it's not working in the site. Using an asp.net web project with a solution file. I put this in the web.config. This will change depending on development database or production database PRODDB via the web configuration transform files and scripts.
<appSettings>
<add key="databaseName" value="DEVELDB"/>
<add key="operatingEnvironment" value="dev"/>
</appSettings>
Within the Global.asax.cs file:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
var operatingEnvironment = WebConfigurationManager.AppSettings["operatingEnvironment"].ToString();
if (operatingEnvironment == "dev")
{
Application["DBE"] = WebConfigurationManager.AppSettings["databaseName"].ToString();
}
}
Within the login.cs class file:
internal static DatabaseConnection GetDatabaseConnection()
{
return
new DatabaseConnection(
new ConnectionProperties
{
User = Shared.User,
Application = Shared.Application,
DatabaseName = (string)HttpContext.Current.Application["DBE"]
});
}
and within the Web.Development.config file there is:
<appSettings>
<add key="databaseName" value="DEVELDB" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="operatingEnvironment" value="dev" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
However, whenever I debug after login, it goes to the code below which is good (the same as coded above) but says Database name was not specified? I have it specified as DEVELDB and using "DBE" to reference it. However, it's not like it debugs to another area and to there, just straight to there and kills it?
...
{
User = Shared.User,
Application = Shared.Application,
DatabaseName = (string)HttpContext.Current.Application["DBE"]
});