There is no need for an intermediate page; the clsSQLBase class should be able to figure out where it's used. Besides, an intermediate page probably wouldn't work because you need this setting on each page that performs data access.
Put the following in the New method of your clsSQLBase class, replacing what was in there:
Code:
Dim keyFromConfig As String = "SqlConnection1.ConnectionString" ' the default setting
Dim myreader As New AppSettingsReader
Try
If HttpContext.Current.Request.ServerVariables.Get("HTTP_HOST").ToLower() = "www.foosite.com" Then
keyFromConfig = "SqlConnection1.ConnectionString"
Else
keyFromConfig = "Name of Config Key for training site"
End If
Catch
Finally
m_connString = myreader.GetValue(keyFromConfig , GetType(System.String))
End Try
The ServerVariables.Get("HTTP_HOST") returns the current server name used, like
www.foosite.com. Based on this name, the web.config key is changed and the correct one is retrieved from the file.
The Try Catch is needed in case this database class is also (accidentally) used in an environment where HttpContext.Current doesn't make any sense, like a desk top application.
Should the code crash, then it defaults back to SqlConnection1.ConnectionString so you always get a value back from the config file.
I haven't tested this code, but I am sure you get the idea.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
The sound of the Big Babou by
Laurent Garnier (Track 4 from the album:
Unreasonable Behaviour)
What's This?