473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 14200
You have as many connection strings as you wish:

<connectionStrings>

<add name="ConnectionString1" connectionString="..."/>

<add name="ConnectionString2" connectionString="..."/>

</connectionStrings>

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*******@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You have as many connection strings as you wish:

<connectionStrings>

<add name="ConnectionString1" connectionString="..."/>

<add name="ConnectionString2" connectionString="..."/>

</connectionStrings>

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(ConfigurationSettings.AppSettings(" mySQLString"))".
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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You have as many connection strings as you wish:

<connectionStrings>

<add name="ConnectionString1" connectionString="..."/>

<add name="ConnectionString2" connectionString="..."/>

</connectionStrings>

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(ConfigurationSettings.AppSettings(" mySQLString"))".
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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You have as many connection strings as you wish:

<connectionStrings>

<add name="ConnectionString1" connectionString="..."/>

<add name="ConnectionString2" connectionString="..."/>

</connectionStrings>

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(ConfigurationSettings.AppSettings(" mySQLString"))".
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 ("mySQLString") so that its (mySQLString). So if you had
the following 2 connection strings:

<add name="ConnectionString1" connectionString="..."/>
<add name="ConnectionString2" connectionString="..."/>

Page_Load
Dim mySQLString As String
Dim strSite As String

strSite = Request.QueryString("Site")

Select Case strSite
Case SiteA
mySQLString = "ConnectionString1"
Case SiteB
mySQLString = "ConnectionString2"
End Select

conn_str = ConfigurationSettings.AppSettings(mySQLString )
conn = New SqlConnection(conn_str)
conn.Open()

Hope this helps!
--

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

"Ibrahim Shameeque" <Ib**************@discussions.microsoft.comwrote in
message news:9F**********************************@microsof t.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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote :
You have as many connection strings as you wish:

<connectionStrings>

<add name="ConnectionString1" connectionString="..."/>

<add name="ConnectionString2" connectionString="..."/>

</connectionStrings>

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(ConfigurationSettings.AppSettings( "mySQLString"))".
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
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...
14
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,...
5
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...
1
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...
2
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...
0
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...
4
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. ...
3
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.