?
Solved

how to loop through web.config and check all items in a section?

Posted on 2008-10-10
2
Medium Priority
?
268 Views
Last Modified: 2013-12-17
i want to test DB connections as sort of a DB health check. i want to have a section in the web config with 6 connection strings called things like DBNewYork, DBCali, DBFlorida... and for a .aspx page to loop over all of them and connect do do some silly select 'true' or something to show the connection worked and DB send a response back.

the ourput of the page should be
[DB name in config1] = true
[DB name in config2] = false
[DB name in config3] = true
...6

this will be nice since to add another DB to check all an admin would do is add a config item and save the new file.
0
Comment
Question by:supergirl2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Salim Fayad earned 2000 total points
ID: 22689788
You put them in your web.config:

<configuration>
     <connectionStrings>
              <add name="ConnectionString1" connectionString="...." />
              <add name="ConnectionString2" connectionString="...." />
              <add name="ConnectionString3" connectionString="...." />
     </connectionStrings>
</configuration>


And in your code:

foreach(ConnectionStringSettings objConnectionString in ConfigurationManager.ConnectionStrings)
{
       string connectionString = objConnectionString.ConnectionString;
}

Open in new window

0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22689793
http://msdn.microsoft.com/en-us/library/ms178411.aspx




Dim rootWebConfig As System.Configuration.Configuration
    rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot")
 
Dim connString As System.Configuration.ConnectionStringSettings
for each connString in rootWebConfig.ConnectionStrings.ConnectionStrings
  'do your thing using connString.ConnectionString as your connection string
next

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question