views:

46

answers:

2

Hi,

I have an application that must be accessed for many users. To optimize the performance I intend to store each user profile information at a independant database file.

I need everytime a user login the application, to setup a new provider linked with his own database. All databases have the same structure. So while querying user the commom generated DAL classes must switch for the database file relative the the user.

Is there a way for configure SubSonic for doing that switch at runtime?

Thanks.

+1  A: 

Well, assuming we 're talking about SubSonic3:

I have made a patch for this and logged it as an issue in the SubSonic Templates project on github, where the source is available. You can find the issue (and a link to the code) here.

After you apply the patch, you will have a new DefaultDataProvider property which does exactly what you want. Use it like this (e.g. after a user logs in):

YourSubSonicGeneratedNamespace.YourDatabaseName.DefaultDataProvider =
    SubSonic.DataProviders.ProviderFactory.GetProvider(
        "your connection string here",
        SubSonic.DataProviders.DbClientTypeName.SqlLite);

And you 're good to go.

For SubSonic 2, this answer sounds like what you want.

Jon
JonI'm using Subsonic 2.0And I have no access to the sourcecode.Is there another alternative?Thanks!
Marcus Vinicius de LIma
@Marcus: updated my answer to point to a relevant SubSonic 2 question.
Jon
A: 

With subsonic 2 I use an approach where I inject the provider at runtime rather than loading it from the app.config file.

Look at my answer here: http://stackoverflow.com/questions/1151240/subsonic-in-a-vs2008-add-in-woes/1152397#1152397

Instead of just using one provider you could create one for every user who starts the application and change the default provider as needed.

SchlaWiener