I have the following code
private string conn(string name)
{
return ConfigurationManager.ConnectionStrings[String.Format("{0}ConnectionString", name)].ConnectionString;
}
But I keep getting the error below on the return statement.
System.NullReferenceException: Object reference not set to an instance of an object
Can you please tell me what is wrong with this?
Your code looks for connection string named name + “ConnectionString”.
It look’s your web.config does not have connection string with this name.
Add connection string with generated name or change the code like this: