Adrian
Adrian

Reputation: 691

How can I get from VB code the connectionStrings?

I have this in web.config and i need to use it from vb to pass it on a variable:

<connectionStrings>
  <clear/>
  <add name="SQL1" connectionString="..." providerName="System.Data.SqlClient"/>
</connectionStrings>

Upvotes: 0

Views: 2863

Answers (4)

Amit
Amit

Reputation: 22076

System.Configuration.ConfigurationManager.ConnectionStrings["SQL1"].ToString();

Upvotes: 0

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

System.Configuration.ConfigurationManager.ConnectionStrings["SQL1"].ConnectionString

Upvotes: 0

faester
faester

Reputation: 15076

You can use the ConfigurationManager in System.Configuration

ConfigurationManager.ConnectionStrings("cnnName").ConnectionString;

Upvotes: 0

Ira Rainey
Ira Rainey

Reputation: 5209

ConfigurationManager.ConnectionStrings("SQL1").ConnectionString.ToString

You'll also need to add Imports System.Configuration is it's not set at the project level.

Upvotes: 1

Related Questions