Friday, February 24, 2012

Connection string question

I'm not sure the best place to put this:

I need help for creating a connection string in VS.Net 2.0. The line that I'm using to create my sql connections is:

<CODE>

Dim connDBAsNew SqlConnection(ConfigurationManager.ConnectionString("TEST").ConnectionString)

</CODE>

"TEST" information is located in the machine.config file.

Anyways, when I type in the line above listed inside the <CODE> brackets, I get the following squiqqly line error under the Configuration Manager

<ERROR>

Name 'ConfigurationManager' is not declared.

</ERROR>

Do I need additional code in my web.config file or somewhere else to use ConfigurationManager? Thanks.

You're probably missing a reference to System.Configuration. It's also ConnectionStrings(), not ConnectionString(). Since it's from Web.config, I normally do it this way:

Imports System.Web.Configuration

Dim connDB As New SqlConnection(WebConfigurationManager.ConnectionStrings("TEST").ConnectionString)

HTH,
Ryan

No comments:

Post a Comment