开发者

'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'

Configuration File

<add key="ObjConn" value="Provider=SQLOLEDB;Persist Security Info=True;Us开发者_开发问答er
ID=OMembers;PWD=OMembers;Initial Catalog=Omnex2007;Data Source=192.168.100.131"/>

C# Code

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


you need to use

ConfigurationManager.AppSettings["ObjConn"]

instead of

ConfigurationManager.AppSettings("ObjConn")

Preferred approach is use below settings in config file

<connectionStrings>   
    <add name="ObjConn" connectionString="your connection string" providerName="System.Data.SqlClient"/>
</connectionStrings>

and use ConfigurationManager.ConnectionStrings["ObjConn"] in your code to retrieve it


try

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

This is one of the language syntax differences between C# and VB. Array accessors in VB use parentheses () while in c# they use square brackets [].

In VB, Something(1) could be calling a function named "Something" and passing a 1 as a parameter, OR it could be that Something is an array or a list, and you're accessing the item at index 1.

in C#, Something(1) is ALWAYS a call to a function named Something, while Something[1] would indicate that Something is an Array or a List, and you're accessing an item in a list.


In C# you should use like

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

change and try again. Generally, the accessing of Config entry values which you have tried in your coding will be used in VB.net coding, but in C# you should use [] with a key name(string format) inside the square brackets, to get the Config entry values.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜