Data layer to use the right connection string based on URL of page request
On my computer I am developing a 3 tier Web application which I publish as two different versions, one for production and one for development purposes: IMP-PROD for production and IMP-DEV for developement. Both connect to their own database: respectively IMPDB-PROD and IMPDB-DEV.
I have one Server with IIS and MS SQL for both Web applications. Each web app have the same hosting url but with a different sub folder name (similar to virtual folders).
I would like the Data Layer to auto detect its URL as to connect to the right database.
The web.config files contains both connection strings,
and I have a Public Class in the data layer that reads those strings
From the datalayer I can detect the CultureInfo but I cannot get session variables which I could use to detects the URL.
Can someone offer me suggestions?
Thanks
P:oD
On my computer I am developing a 3 tier Web application which I publish as two different versions, one for production and one for development purposes: IMP-PROD for production and IMP-DEV for developement. Both connect to their own database: respectively IMPDB-PROD and IMPDB-DEV.
I have one Server with IIS and MS SQL for both Web applications. Each web app have the same hosting url but with a different sub folder name (similar to virtual folders).
I would like the Data Layer to auto detect its URL as to connect to the right database.
The web.config files contains both connection strings,
and I have a Public Class in the data layer that reads those strings
From the datalayer I can detect the CultureInfo but I cannot get session variables which I could use to detects the URL.
Can someone offer me suggestions?
Thanks
P:oD
Code:
----- presentation layer ------- ------- web.config ------ <add name="SqlConnIMP-PROD" connectionString="data source=(local)\sqlexpress;Database=IMP;Trusted_Connection=True" providerName="System.Data.SqlClient"/> <add name="SqlConnIMP-DEV" connectionString="data source=(local)\sqlexpress;Database=IMP-DEV;Trusted_Connection=True" providerName="System.Data.SqlClient"/> -------- data layer ---------- Public Class DatabaseHelper Friend Shared Function GetSqlConnIMP() As SqlConnection Dim RightConnectionstring As String = "SqlConnIMP-PROD" 'Good Code needed here If DevEnvironment Then RightConnectionstring = "SqlConnIMP-DEV" End If Return New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(RightConnectionstring).ConnectionString) End Function
Comment