I created a data access adapter factory component that lets an applicaton use multiple database adapters and as many connection strings as needed. It is also thread safe. Here is a sample of what the xml looks like in the app config. It can also be specified at run time:
<sheakley.framework>
<sheakley.data>
<dataAccessAdapters>
<dataAccessAdapter name="WC" commandTimeout='300' type='Sheakley.Evolution.Data.DatabaseSpecific.DataAccessAdapter,Sheakley.Evolution.DataDBSpecific'>
<connectionStrings defaultConnectionString="Production" symmetricName='RijndaelManaged'>
<connectionString name='Production' catalog='E0x5bpih9SusghXxrUAs/2YsOAtVsqP3jfGQE9haKws=' value="ZczSwRnJzCmU1RbJzahrJo" />
<connectionString name='Test' catalog='3CsHY7SHFxE9o1iDwg/gum+Mszc5no=' value="R3xh2IwAmP6RUhoDqAh8IKZCijuxqhp6" />
</connectionStrings>
</dataAccessAdapter>
<dataAccessAdapter name="Corp" commandTimeout='500' type='Sheakley.Evolution.Data.DatabaseSpecific.DataAccessAdapter,Sheakley.Evolution.DataDBSpecific'>
<connectionStrings defaultConnectionString="Production" symmetricName='RijndaelManaged'>
<connectionString name='Production' catalog='E0x5bpih9SusghXxrUAs/2YsOAtVsqP3jfGQE9haKws=' value="ZczSwRnJzCmU1RbJzahrJo" />
<connectionString name='Test' catalog='3CsHY7SHFxE9o1iDwg/gum+Mszc5no=' value="R3xh2IwAmP6RUhoDqAh8IKZCijuxqhp6" />
</connectionStrings>
</dataAccessAdapter>
</dataAccessAdapters>
</sheakley.data>
</sheakley.framework>
Here is a few methods that make use:
Private Const DATA_ACCESS_ADAPTER_CONFIG_KEY = "WC"
Public Shared Sub ChangeEnvironment(ByVal environment As System.String)
DataAccessAdapterManager.GetManager().ChangeDefaultConnectionString(environment)
End Sub
Public Shared Sub ChangeCommandTimeout(ByVal commandTimeout As System.Int32)
DataAccessAdapterManager.GetManager().ChangeDefaultCommandTimeout( _
DATA_ACCESS_ADAPTER_CONFIG_KEY, commandTimeout _
)
End Sub
Public Shared Function GetAvailableEnvironments() As System.String()
Return DataAccessAdapterManager.GetManager().GetAvailableConnectionStringTypes( _
DATA_ACCESS_ADAPTER_CONFIG_KEY _
)
End Function
Public Shared Function GetCurrentEnvironment() As System.String
Return DataAccessAdapterManager.GetManager().GetCurrentConnectionStringType(DATA_ACCESS_ADAPTER_CONFIG_KEY)
End Function
Friend Shared Function CreateDataProvider() As IDataAccessAdapter
Return DataAccessAdapterManager.GetManager().Create(DATA_ACCESS_ADAPTER_CONFIG_KEY)
End Function
If you send me your email, I can shoot you the code. Also, it uses the MS App Block for the encryption, but I should really re-factor the code and use a strategy to handle the encryption, but you can just comment that portion out if need b.