using an xml file to store a pre-connection value---

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like the administrator for my web site to be able to select between a
'Production' back-end or a 'Backup' backend.

There are 2 values in the Web.Config file, but I know that the point that it
connects using the web.config information is already too late.

My current connection is setup as follows:
Public Shared Function GetMembershipConnection() As SqlConnection
'Return New SqlConnection(GetConnectionString)
Return New
SqlConnection(DecryptConnectionString(GetConnectionString))
End Function

Public Shared Function GetConnectionString() As String
Dim sMemberCon As String =
ConfigurationManager.ConnectionStrings("SQLConn").ConnectionString
Return sMemberCon
End Function

What I would like to do is, change a value in an xml file and use this as a
pre-check to determine what connection string to use SQLConn or SQLConn2

But I've never worked with XML in this manner ...
 
Hi jonefer,
Instead of saving it in a different xml file, you could use the AppSettings
section in the web.config.

For example, add in this code to the web.config below <configuration>
<appSettings>
<add key="ConnectionIndex" value="1"/>
</appSettings>

And then you can retrieve that value to decide which connection to use:

Public Shared Function GetConnectionString() As String
Dim sMemberCon As String
If ConfigurationManager.AppSettings("ConnectionIndex") = "1" Then
sMemberCon =
ConfigurationManager.ConnectionStrings("SQLConn1").ConnectionString
Else
sMemberCon =
ConfigurationManager.ConnectionStrings("SQLConn2").ConnectionString
End If
Return sMemberCon
End Function


The code probably won't compile, but it is just to give you an idea.
Best Regards,
 
Yes, but how can an administrator now change that value from 1 to 0 - from
within in my application? (By administrator, I mean someone in our company
who knows nothing about IIS and only knows that they would like to switch to
a different back end)

It wasn't a question of writing the logic to switch between SQLConn1 and 2,
it was a question of how I could get that number 0 or 1 stored somewhere when
the administrator pushes a button.
 
Back
Top