Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello all,

My application is in VB.net and I am having one clsdatabase class.
In that i am having source code like below for connection string.

con = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConString1"));


but the same thing i want to implement in C#...

I just converted that in to

con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConString1"))


but it will blow error while execution.

Non-Invocable member.

System.Configuration.ConfigurationManager.AppSettings cannot be used like a method...


So how can i tackle that?
Posted
Updated 22-May-11 5:15am
v2

Change the brackets!
con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConString1"))
Becomes
con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strConString1"])
 
Share this answer
 
Comments
Valery Possoz 22-May-11 10:03am    
Oops! I did not notice you had already answered.
NuttingCDEF 22-May-11 10:05am    
Quick and simple - my 5 to both!
Kim Togo 22-May-11 11:49am    
Good answer
YOGESH DHAGE 22-May-11 11:50am    
yes its work
thanks for quick response
Hello.

I think the correct way to write this in C# is:

System.Configuration.ConfigurationManager.AppSettings[keyName]


(Square brackets.)

Valery.
 
Share this answer
 
Comments
OriginalGriff 22-May-11 10:05am    
I do it all the time!
Kim Togo 22-May-11 11:49am    
Great answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900