开发者

Compiler Error Message: CS0118: 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'

开发者 https://www.devze.com 2023-04-06 07:28 出处:网络
Compiler Error Message: CS0118: \'System.Configuration.ConfigurationManager.AppSettings\' is a \'property\' but is used like a \'method\'

Compiler Error Message: CS0118: 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'

<add key="ObjConn" value="Provider=SQLOLEDB;Persist Secur开发者_JAVA技巧ity Info=True;User ID=OMembers;PWD=OMembers;Initial Catalog=Db;Data Source=""/>

 strconnection = System.Configuration.ConfigurationManager.AppSettings("ObjConn");
          sqlcon = new SqlConnection(strconnection);


in C#, do this:

strconnection = System.Configuration.ConfigurationManager.AppSettings["ObjConn"];
sqlcon = new SqlConnection(strconnection);


I believe you're working in C#? You need to access it using index operator:

strconnection = System.Configuration.ConfigurationManager.AppSettings["ObjConn"];


Better to define connection strings in the connection strings section as so:

<connectionStrings>
   <add 
      name="ObjConn" 
      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 
      providerName="System.Data.SqlClient"
   />
</connectionStrings>

And instantiate you SqlConnection like this:

strconnection = System.Configuration.ConfigurationManager.ConnectionStrings["ObjConn"].ConnectionString;
sqlcon = new SqlConnection(strconnection);
0

精彩评论

暂无评论...
验证码 换一张
取 消