Hi Doug,
From your description, you encountered some problem when tried retrieving
connectionstrin gs from ASP.NET web.config programmtically , correct?
According to the code you provided, I think the problem is due to the
"ConfigurationS ettings" class you used. In .NET framework 2.0 application,
you can use the following means to read connectionstrin g (in
<connectionStri ngssection in app.config or web.config):
1. For ASP.NET application, you can use the
System.Web.Conf iguration.WebCo nfigurationMana ger class's
"ConnectionStri ngs" property to access connectionstrin gs defined in
web.config file, e.g.
=============== ==========
using System.Web.Conf iguration;
......
protected void Page_Load(objec t sender, EventArgs e)
{
foreach (ConnectionStri ngSettings connstr in
WebConfiguratio nManager.Connec tionStrings)
{
Response.Write( "<br/>" + connstr.Name + ": " +
connstr.Connect ionString);
}
}
=============== ===
2. Or you can use "System.Configu rationManager.C onnectionString s" property,
this will work in not only ASP.NET Web application, but also other desktop
application(con sole or winform):
=============== =====
protected void Page_Load(objec t sender, EventArgs e)
{
foreach (ConnectionStri ngSettings connstr in
ConfigurationMa nager.Connectio nStrings)
{
Response.Write( "<br/>" + connstr.Name + ": " +
connstr.Connect ionString);
}
}
=============== ==========
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "dbuchanan" <db*******@news group.nospam>
Subject: How to retreve connection string programmaticaly from this
Date: Tue, 15 Jul 2008 01:25:38 -0400
>
Here is part of the web.config - it is given to me like this.
============== =========
<configuration >
<appSettings/>
<connectionStri ngs>
<add name="MyConnect ionName" connectionStrin g="Data
Source=MyServe rName;Initial Catalog=MyDatab aseName;Integra ted
Security=True"
>providerName=" System.Data.Sql Client"/>
</connectionStrin gs>
<system.web>
============== =========
How do I get the connection string?
The follwoing code is my attempt to connect
string cnStr;
cnStr = ConfigurationSe ttings. << At this point intellisense gives me the
following:
AppSettings
Equals
GetConfig
ReferencEqua ls
Introducing Microsoft ASP.NET 2.0 Shows a different suggests the following
code
cnStr =
ConfigurationS ettings.conneci onStrings["MyConnectionNa me"].ConnectionStri ng
;
>
However I get the following error
Error 1 'System.Configu ration.Configur ationSettings' does not contain a
definition for 'connecionStrin gs' C:\Documents and
Settings\Admini strator\My
>Documents\Visu al Studio 2005\WebSites\W ebSiteCompletio nReport\Default .aspx
13 41 C:\...\WebSiteC ompletionReport \