In VB.NET, I can use:
Protected Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Active").ConnectionString)
However, when I do the following in C #:
protected SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings("conn"));
I get an error message:
The name "ConfigurationManager" does not exist in the current context
Then if I change it to:
protected SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("conn"));
I get an error message:
The non-invoking member of 'System.Configuration.ConfigurationManager.ConnectionStrings' cannot as a method.
Why is this and how can I connect to my SQL Server database using C #?
source share