471,330 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Implement Connections from machine.config

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,

Jul 3 '08 #1
3 1374
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
Jul 3 '08 #2

"Girish" wrote:
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>

--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 3 '08 #3
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:am*****@gmail.com; blog:devkids.blogspot.com
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,

Jul 3 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Raghu Rudra | last post: by
4 posts views Thread by Matt Anderson | last post: by
9 posts views Thread by stephen | last post: by
6 posts views Thread by TulasiKumar | last post: by
11 posts views Thread by TARUN | last post: by
5 posts views Thread by jacques.steward | last post: by
5 posts views Thread by =?Utf-8?B?SmVycnkgQw==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.