tags:

views:

42

answers:

2

I may be a bit over my head here - but hopefully someone can point me in the right direction.

Using the latest SOURCE files for SubSonic 2 - I need to be able to manipulate the CONNECTIONSTRING for specific requests based on the USER.

I thought I could modify DefaultConnectionString is DataProvider.cs - but HttpContext.Current ALWAYS seems to be null when that property is called (even when it is through a http request.)

When is that called by SubSonic? I'm assuming it is at a point when the page lifecycle DOESN'T exist and therefore the HTTPCONTEXT/PROFILE data is always missing.

Is there any way to work around this? Basically I have several identical structure databases I wish to access using SubSonic (same structures) and I want to choose the DB to use based on the current user's profile, any suggestions?

+1  A: 

You can specify multiple providers in your config and then choose which to use at runtime. See the following question for details of how:

http://stackoverflow.com/questions/828736/separate-read-write-connection-for-subsonic/828825#828825

Adam
+1  A: 

If you rely on multiple providers in web.config still won't help you attach to new databases at runtime since you will have hardcoded the connection strings. For a windows forms application, switching connection strings is very easy. For a web app you have to be very certain that simultaneous web sessions see only their assigned database. There are a lot of statics in ss2x that make this less than easy.

This was covered before and you can use this as a google search: "shareddbconnectionscope site:http://subsonicproject.com"

Many of the old forum discussions and code samples are gone now.

There is some information in the docs. http://www.subsonicproject.com/docs/3.0_Multiple_Databases

I thought this was an interesting thread. Most ORMs don't really deal with multiple databases very well: http://stackoverflow.com/questions/1121753/am-i-the-only-one-that-queries-more-than-one-database

P a u l