编译器错误消息:CS0118:' System.Configuration.ConfigurationManager.AppSettings'是一个属性'但是像''
一样使用<add key="ObjConn" value="Provider=SQLOLEDB;Persist Security Info=True;User ID=OMembers;PWD=OMembers;Initial Catalog=Db;Data Source=""/>
strconnection = System.Configuration.ConfigurationManager.AppSettings("ObjConn");
sqlcon = new SqlConnection(strconnection);
答案 0 :(得分:7)
C#
中执行此操作:
strconnection = System.Configuration.ConfigurationManager.AppSettings["ObjConn"];
sqlcon = new SqlConnection(strconnection);
答案 1 :(得分:3)
我相信你在C#工作?您需要使用索引运算符访问它:
strconnection = System.Configuration.ConfigurationManager.AppSettings["ObjConn"];
答案 2 :(得分:2)
最好在连接字符串部分中定义连接字符串,如下所示:
<connectionStrings>
<add
name="ObjConn"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
并像这样实例化你的SqlConnection:
strconnection = System.Configuration.ConfigurationManager.ConnectionStrings["ObjConn"].ConnectionString;
sqlcon = new SqlConnection(strconnection);