473,698 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple connection string in web.config

My development machine has Win XP pro and IIS 5.1
I have a 'default web site' with 2 virtual directories, let's say
'siteA' and 'siteB'.
Both point to the same application in the same phisical directory,
let's say C:\web\mysite.
In the 'web.config' file I have a key ('mysqlstring') that defines the
connection string to the database.
Is it possible to have two connection strings depending one the site I
use?
So if I came from 'http://localhost/siteA' I will use database 'A '
and if I came from 'http://localhost/siteB' I will use database 'B'
with the same application?
Thank you for your replay

Oct 24 '07 #1
5 14212
You have as many connection strings as you wish:

<connectionStri ngs>

<add name="Connectio nString1" connectionStrin g="..."/>

<add name="Connectio nString2" connectionStrin g="..."/>

</connectionStrin gs>

and in the code you can check the request url to decide what connection
string to use. Page.Request property points to the HttpRequest object that
in turn provides various url-related properties.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"wild" <wi*******@gmai l.comwrote in message
news:11******** **************@ z24g2000prh.goo glegroups.com.. .
My development machine has Win XP pro and IIS 5.1
I have a 'default web site' with 2 virtual directories, let's say
'siteA' and 'siteB'.
Both point to the same application in the same phisical directory,
let's say C:\web\mysite.
In the 'web.config' file I have a key ('mysqlstring') that defines the
connection string to the database.
Is it possible to have two connection strings depending one the site I
use?
So if I came from 'http://localhost/siteA' I will use database 'A '
and if I came from 'http://localhost/siteB' I will use database 'B'
with the same application?
Thank you for your replay

Oct 24 '07 #2
On 24 Ott, 14:30, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
You have as many connection strings as you wish:

<connectionStri ngs>

<add name="Connectio nString1" connectionStrin g="..."/>

<add name="Connectio nString2" connectionStrin g="..."/>

</connectionStrin gs>

and in the code you can check the request url to decide what connection
string to use. Page.Request property points to the HttpRequest object that
in turn provides various url-related properties.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Thank you for your replay but I don't want to correct the code already
written in a lot of routines,
something like "Dim MyConn As New
OdbcConnection( ConfigurationSe ttings.AppSetti ngs("mySQLStrin g"))".
I was asking if it is possible to have two different 'config' files
depending on the requesting url, and leave the code unchanged.

Oct 24 '07 #3
On 24 Ott, 14:30, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
You have as many connection strings as you wish:

<connectionStri ngs>

<add name="Connectio nString1" connectionStrin g="..."/>

<add name="Connectio nString2" connectionStrin g="..."/>

</connectionStrin gs>

and in the code you can check the request url to decide what connection
string to use. Page.Request property points to the HttpRequest object that
in turn provides various url-related properties.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Thank you for your replay but I don't want to correct the code already
written in a lot of routines,
something like "Dim MyConn As New
OdbcConnection( ConfigurationSe ttings.AppSetti ngs("mySQLStrin g"))".
I was asking if it is possible to have two different 'config' files
depending on the requesting url, and leave the code unchanged.

Oct 24 '07 #4
Did you have a look at asp.net configuration settings under virtual directory
properties in IIS?

Also, you could have two start pages, one for each virtual directory, which
sets the database connection.
Thanks
---------------------------
Thanks,
Ibrahim

Software Consultant - Web Development, GB
"wild" wrote:
On 24 Ott, 14:30, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
You have as many connection strings as you wish:

<connectionStri ngs>

<add name="Connectio nString1" connectionStrin g="..."/>

<add name="Connectio nString2" connectionStrin g="..."/>

</connectionStrin gs>

and in the code you can check the request url to decide what connection
string to use. Page.Request property points to the HttpRequest object that
in turn provides various url-related properties.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Thank you for your replay but I don't want to correct the code already
written in a lot of routines,
something like "Dim MyConn As New
OdbcConnection( ConfigurationSe ttings.AppSetti ngs("mySQLStrin g"))".
I was asking if it is possible to have two different 'config' files
depending on the requesting url, and leave the code unchanged.

Oct 24 '07 #5
You could set the connection string as follows (air code). Then all you
have to do is run the replace command on the application to remove the
parenthesis around ("mySQLStrin g") so that its (mySQLString). So if you had
the following 2 connection strings:

<add name="Connectio nString1" connectionStrin g="..."/>
<add name="Connectio nString2" connectionStrin g="..."/>

Page_Load
Dim mySQLString As String
Dim strSite As String

strSite = Request.QuerySt ring("Site")

Select Case strSite
Case SiteA
mySQLString = "ConnectionStri ng1"
Case SiteB
mySQLString = "ConnectionStri ng2"
End Select

conn_str = ConfigurationSe ttings.AppSetti ngs(mySQLString )
conn = New SqlConnection(c onn_str)
conn.Open()

Hope this helps!
--

*************** ***
Reggie

"Ibrahim Shameeque" <Ib************ **@discussions. microsoft.comwr ote in
message news:9F******** *************** ***********@mic rosoft.com...
Did you have a look at asp.net configuration settings under virtual
directory
properties in IIS?

Also, you could have two start pages, one for each virtual directory,
which
sets the database connection.
Thanks
---------------------------
Thanks,
Ibrahim

Software Consultant - Web Development, GB
"wild" wrote:
>On 24 Ott, 14:30, "Eliyahu Goldin"
<REMOVEALLCAPI TALSeEgGoldD... @mMvVpPsS.orgwr ote:
You have as many connection strings as you wish:

<connectionStri ngs>

<add name="Connectio nString1" connectionStrin g="..."/>

<add name="Connectio nString2" connectionStrin g="..."/>

</connectionStrin gs>

and in the code you can check the request url to decide what connection
string to use. Page.Request property points to the HttpRequest object
that
in turn provides various url-related properties.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Thank you for your replay but I don't want to correct the code already
written in a lot of routines,
something like "Dim MyConn As New
OdbcConnection (ConfigurationS ettings.AppSett ings("mySQLStri ng"))".
I was asking if it is possible to have two different 'config' files
depending on the requesting url, and leave the code unchanged.


Oct 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2769
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
14
3498
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that web.config file is protected by IIS and Windows security which is the case. And another argument is that...
5
1868
by: Mike TI | last post by:
May 2, 2006 Hi All I have been learning VB.Net 2005 by developing a small project. I have been using SQL Express till now. Now I have built a similar to SQL Data Base in MS Access. I tried to use the MS Access Data Base in my application but am unable to do so.
1
5140
by: Matt F | last post by:
Two of the projects in my solution that both need to use a common user.config file. This is a data application - the executable that is created with the first project is the primary executable that users will be working with 99% of the time, the other is a seperate "maintenance" executable. The connection string is stored via My.Settings (encrypted of course). The problem is that obviously with 2 different .exe there are 2 seperate...
2
6607
by: Thorsten Dittmar | last post by:
Hi, I don't get it. I'm using a typed dataset with table adapters and all that stuff. I have the database server running locally on my development system. Now: when creating a tableadapter I'm asked for the connection and the connection string is automatically stored in the settings. So far so good. However, my typed dataset is declared within a dll that implements other
0
1477
by: nospam | last post by:
Hello everyone, I have a newbie question that I am sure you have probably encountered. I am developing a ASP NET app that interfaces to a database ( SqlServer). When I am developing I use my local version of MSSQL - so the connection string has something like: connectionString="Data Source=myLocalMachine;Initial Catalog=my_db;Persist Security Info=True;User ID=...etc" But when the app is released, I have to change...
4
8496
by: David W | last post by:
We have a setup where we have a single web application, but the user can be attached to any of a hundred different (identically structured) databases depending on their login credentials. Currently we are storing the connection string in Session and in each page's Page_Init we reset any SqlDataSource's connection string. This works reasonably well, though not ideal: SqlDataSource1.ConnectionString = Session("dbconn") I would like to...
3
4009
by: =?Utf-8?B?QXZpc2hheSBCZW4tWnZp?= | last post by:
Hi, I have an application that I am encrypting the connection strings on the first run of the application. I am using clickonce to deploy the application, so this was a good solution as the application is immediately run and the config file is encrypted immediately. How ever, when the application is deployed a second directory with "_none_" in the name is created and the app.config is copied there too.The app.config in the _none_...
2
5391
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy ASP.NET applications that all manage connection strings in Web.config the same way, like this: This client has one Web.config file per application, and that one Web.config file is duplicated across all environments (i.e., dev machines, test,...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.