In case you need to open a connection manually or just need to know what database you currently working with.
- Proceed to output folder and open web.config file in text editor. You will find <connectionStrings> section there:
<connectionStrings>
<add name="livedemo_northwind_at_localhost" connectionString="Server=localhost;Database=livedemo_northwind;User Id=root;Password=" />
</connectionStrings>
Notice the name of connection string: "livedemo_northwind_at_localhost"
2. Here is the code that reads connection string and prints it on the page. Replace "livedemo_northwind_at_localhost" with your connection string name.
System.Configuration.Configuration rootWebConfig =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot");
System.Configuration.ConnectionStringSettings connString;
if ( rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0) {
connString = rootWebConfig.ConnectionStrings.ConnectionStrings["livedemo_northwind_at_localhost"];
if ( connString != null) {
MVCFunctions.Echo(connString.ConnectionString);
}
}