Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I read all the connection strings from web.config without the names of each one? ASP.net

I want to read all the connection strings from web.config programmatically without specifying the names of the connection strings. And use that information for different purposes e.g. print out on the screen. Is it possible and how can I do that?

Thanks,

like image 468
Laurence Avatar asked Dec 20 '25 05:12

Laurence


1 Answers

You obviously did not try anything. This would do it

  foreach (var s in System.Web.Configuration.WebConfigurationManager.ConnectionStrings)
  {
        Response.Write(s);
  }

Where ConnectionStrings is a collection of ConnectionStringSettings

foreach (System.Configuration.ConnectionStringSettings s in System.Web.Configuration.WebConfigurationManager.ConnectionStrings)
{
     Response.Write(s);
}
like image 64
codingbiz Avatar answered Dec 22 '25 19:12

codingbiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!