Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Problem with Connection String for Visual Webpart

$
0
0

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"


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>