Implement Connections from machine.config

  • Thread starter Thread starter Girish
  • Start date Start date
G

Girish

I have two application running in one server, both have same
sqlserver connection strings in their web.config files. i want to
combine both connection strings in one config file.
please suggest me, can i implement those connection strings in
machine.config file and use connections from their.

i have tried it, but unable to implement

Please help.

Thanks,
 
First - I'm assuming you are using .NET 2.0 or higher; with 1.1 all
bets are off...

The simplest option is just to duplicate the connection strings
between apps; this means you can simply "robocopy" the site to a new
server and it will work - but I appreciate that this might complicate
configuration (even with an automated configuration/deployment
process, you might need to change the keys post-deployment to cope
with server changes - and it is nice to do this in one centralised
place).

The machine.config should already include this, with the
"LocalSqlServer" default. Adding extras to here should work fine as
long as you don't have a <clear/> element at any level. You should be
able to do the same in the master web.config if it is running ASP.NET;
another option for ASP.NET is to have a web.config in the site root
with the necessary options, but some entries in here will break things
if you have any legacy ASP.NET 1.1 sites (since they will attempt to
parse the same root web.config). You can get around this if you need
(using the "location" element).

Note that editing the machine.config or the master web.config (without
using "location") is not recommended if you are hosting isolated sites/
apps that shouldn't know about eachother, as these keys will leak
information between sites - but as long as your apps are all under
your control it should be OK.

Marc
 
Girish said:
I have two application running in one server, both have same
sqlserver connection strings in their web.config files. i want to
combine both connection strings in one config file.
please suggest me, can i implement those connection strings in
machine.config file and use connections from their.

i have tried it, but unable to implement

Please help.

Thanks,

Hi Girish,

Yes, you can set common connectionstrings in Machine.Config

In fact, I found one there already, accessible to both windows and web
applications

ConnectionStringSettings conn =
ConfigurationManager.ConnectionStrings["LocalSqlServer"];

Remember to put it on the configuration level

<configuration>
<connectionStrings>
<add name="LocalSqlServer" connectionString="..."
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
 
Hi Girish,

machine.config impacts on all applications and conflicts there might ruin
everyones. So, how about to implement configuration providing service holds
information about environments? Take a look on UDDI concepts.

Regards, Alex Meleta
mailto:[email protected]; blog:devkids.blogspot.com
 
Back
Top