I am getting Object reference not set to an instance of an object when using the connection string below. The exact same string works in a custom control, but for some reason the visual webpart doesn't recognize it. I have System.Configuration as a reference and there are no indications of a problem until you load the page with the webpart. If I hard code the connection string it works fine, but I would definitely prefer using the config file.
This doesn't work:
protected string cnMyDB = ConfigurationManager.ConnectionStrings["MyDBName"].ConnectionString;
hard coded works:
protected string cnMyDB = "Database=MyDBname;Server=MyServer;Integrated Security=false;Persist Security Info=True;uid=myUID;pwd=myPWD"