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" />
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();
请尝试以下操作:
ConfigurationManager.ConnectionStrings["myConnection"].ToString()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.