In this post you are going to take a look at Distributed ConnectionString in ASP.NET. We will store our configuration settings in separate configuration file (that's I am calling distributed).
Managing huge list of ConnectionStrings in one configuration file (Web.config) is one of the difficult jobs in ASP.NET based web designing. So, I am writing this video post for you that will light a way to deal.
Also, Web.config file has much information already so placing connection strings in that creates management difficulties if you work on big projects.
What I am going to do?
I have a Web.config file in my project that has following information (including connection strings):
<?xml
version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\vx.x\Config
-->
<configuration>
<connectionStrings>
<add
name="ConnStr1"
connectionString="infos***"/>
<add
name="ConnStr2"
connectionString="infos***"/>
<add
name="ConnStr3"
connectionString="infos***"/>
<add
name="ConnStr4"
connectionString="infos***"/>
<add
name="ConnStr5"
connectionString="infos***"/>
<add
name="ConnStr6"
connectionString="infos***"/>
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation
debug="true">
<assemblies>
<add
assembly="System.Core,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add
assembly="System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add
assembly="System.Data.DataSetExtensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add
assembly="System.Xml.Linq,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication
mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add
tagPrefix="asp"
namespace="System.Web.UI"
assembly="System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add
tagPrefix="asp"
namespace="System.Web.UI.WebControls"
assembly="System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove
verb="*"
path="*.asmx"/>
<add
verb="*"
path="*.asmx"
validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add
verb="*"
path="*_AppService.axd"
validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add
verb="GET,HEAD"
path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
validate="false"/>
</httpHandlers>
<httpModules>
<add
name="ScriptModule"
type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>


Join the conversation! Your thoughts help the community grow.