我在web.config文件中有以下连接字符串,当我运行时出现错误
“对象未设置为对象实例”
在以下行。我正在使用sql server 2012 db和visual studio 2010。
dbConnectionString = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
配置
<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" />
答案 0 :(得分:1)
试试这个
配置:
<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>
在代码中:
string _connection = ConfigurationManager.AppSettings [“myConnection”]。ToString();
答案 1 :(得分:0)
尝试以下方法:
ConfigurationManager.ConnectionStrings["myConnection"].ToString()