This is relatively old topic but looks like still relevant. You need to know why?
Story
Recently one of our vendor deployed an app in one of our environment and when tested, found that the some of the entries going to wrong DB. Checked the connection strings in Web.Config, everything was fine. Due to the lack of proper logging in the application, we planned to hook up Microsoft Azure Application Insights, and we did discovered something, thanks to AI.
Application Map in the #Azure #applicationinsights saved us.
— Abhith Rajan (@AbhithRajan) September 14, 2019
We were able to catch a wrong connection string hardcoded in a vendor dll by checking the Application Map in the AI.@AppInsights 👏 👏 👏
Hard coding something like Connection String is a BAD PRACTICE, things like that should come as a parameter to the class library methods. Since we are not in a position to rewrite everything, what we did was, we replaced the hard coded connection string with the actual connection string value from the web.config.
using System.Configuration;
...
public static string ConnectionString
{
get { return ConfigurationManager.ConnectionStrings["Default"].ConnectionString; }
}
In the above code, Default
is the connection string name in the web.config.