Find solution

How do I connect to SQL Server using C#?

Here are 17 best answers to ‘How do I connect to SQL Server using C#?’ - the most relevant comments and solutions are submitted by users of Stack Overflow, Yahoo! Answers and Quora.

Best solution

  • SqlConnection in C#

    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 the error: 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...

    Answer:

    Try like this: protected SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings...

    Mark as irrelevant Undo

Other solutions