Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble accessing web config for connection string

Status
Not open for further replies.

hrhadin

Programmer
Oct 7, 2003
16
0
0
US
I have the following entry in my web.config file:

<connectionStrings>
<add name="ConnectionString" connectionString="Server=XXX\SQLEXPRESS;Database=Test;Uid=sa;Pwd=XXXXX"></add>
</connectionStrings>

I am trying to access the connection string as follows:

Dim lcConStr As String
lcConStr = ConfigurationManager.AppSettings("ConnectionString")
txtLocation.Text = lcConStr

When ran, the textbox comes up empty. What could be the problem?

 
... = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
 
You've used the COnfigurationManager's AppSetting method which would retrieve an entry from this section:
Code:
	[b]<appSettings>[/b]
		<add key="myKey" value="myValue"/>
	[b]</appSettings>[/b]
As TipGiver said, if you want to retrieve a value from the connectionStrings section, you'll have to use the method suggested.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks to you both. I'm a beginner with ASP.NET and it's a steep learning curve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top