Reputation: 181
I have the following connection string in the web.config file, when I run I get an error
"Object not set to an instance of object"
at the following line. I am using sql server 2012 db and visual studio 2010.
dbConnectionString = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
Config
<connectionStrings>
<add name="myConnection" connectionString="Data Source=sag-pc\;Initial Catalog=BalloonShop;Persist Security Info=True;User ID=sa;Password=pwd" providerName="System.Data.SqlClient" />
Upvotes: 1
Views: 144
Reputation: 1144
Try this
Config :
<appSettings>
<add key="myConnection" value="Data Source=sag-pc;Initial Catalog=BalloonShop;Persist Security Info=True;User ID=sa;Password=pwd;providerName=System.Data.SqlClient"/>
</appSettings>
In Code :
string _connection=ConfigurationManager.AppSettings["myConnection"].ToString();
Upvotes: 1
Reputation: 417
Try the following:
ConfigurationManager.ConnectionStrings["myConnection"].ToString()
Upvotes: 0