C# ConnectionStringName

  • Thread starter Thread starter jp2msft
  • Start date Start date
J

jp2msft

Using VB, I can access the database connection string (or other application
settings) using:

Dim myconnStr As String = My.Settings.ConnectionStringName

What is the equivalent in C#?
 
ConfigurationManager.ConnectionStrings["{Connection String Name}"]


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
Some things from VB to C# just aren't as simple as you'd think!

I kept looking for something under the "this" keyword.

Thanks, Cowboy!

Cowboy (Gregory A. Beamer) said:
ConfigurationManager.ConnectionStrings["{Connection String Name}"]


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
jp2msft said:
Using VB, I can access the database connection string (or other
application
settings) using:

Dim myconnStr As String = My.Settings.ConnectionStringName

What is the equivalent in C#?
 
Wasn't able to get my system to recognize 'ConfigurationManager'. In the
Help, I saw it was part of System.Configuration, but it still did not appear
even after adding "#using System.Configuration;".

How are you getting this?

Cowboy (Gregory A. Beamer) said:
ConfigurationManager.ConnectionStrings["{Connection String Name}"]


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
jp2msft said:
Using VB, I can access the database connection string (or other
application
settings) using:

Dim myconnStr As String = My.Settings.ConnectionStringName

What is the equivalent in C#?
 
Try Settings.Default.ConnectionStringName

jp2msft said:
Wasn't able to get my system to recognize 'ConfigurationManager'. In the
Help, I saw it was part of System.Configuration, but it still did not
appear
even after adding "#using System.Configuration;".

How are you getting this?

Cowboy (Gregory A. Beamer) said:
ConfigurationManager.ConnectionStrings["{Connection String Name}"]


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
jp2msft said:
Using VB, I can access the database connection string (or other
application
settings) using:

Dim myconnStr As String = My.Settings.ConnectionStringName

What is the equivalent in C#?
 
Hi,

Normally:
ConfigurationSettings.AppSettings["TheNameOfTheString"];

Be aware that the "my" class is only an extra shared class (static in C#) in
VB for Net that is created to make it easier for old VB6 users to go to VB
for Net.

The code above with the difference of the brackets can as well be used in VB
for Net.

Cor
 
Back
Top