views:

117

answers:

1

I have an application build using ActiveRecord for which there is a new requirement to allow the user to select a database they wish to operate at various times in the course of the running of the application.

The database connection is set up in the ActiveRecordStart.Initalize call. I would like to be able to change this connection whenever the user selects to work with a new database. However, I can see no way of doing this.

DifferentDatabaseScope does allow the use of a different connection, but only overrides the connection setup in the Initialize call and has to be used for each ActiveRecord call, which number hundreds, so is less than ideal.

This there some way I am not aware of to change the 'base' connection that is set up in the Initialize?

A: 

If DifferentDatabaseScope is not enough try writing a custom IConnectionProvider that creates a IDbConnection pointing to the user-selected database.

Mauricio Scheffer