Dave Mackey
Dave Mackey

Reputation: 4432

How to tell ConfigurationManager.ConnectionStrings to pull specific connection string

I'm using some Microsoft sample code and they have an example of using ConfigurationManager.ConnectionStrings to pull a series of connection strings from the app.config and allow an individual to choose the string they want. I don't need the ability to choose, I just want to get the specific named connection string I have defined. Something like (yes, I know this isn't real code):

Configuration.ConnectionStrings.Select("myconnection")

Is this possible? If not, how should I pull in a single connection string?

Upvotes: 0

Views: 254

Answers (2)

Andre Pena
Andre Pena

Reputation: 59446

ConfigurationManager.ConnectionStrings["my_connection"].ConnectionString

Upvotes: 1

indiPy
indiPy

Reputation: 8072

You need to reference System.Configuration.ConfigurationManager

      ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString

Upvotes: 2

Related Questions