views:

48

answers:

3

Suppose you have a single web portal application that is used by a number of different clients. For reasons of security and portability, each client's data must reside in a separate database. The schema for each of these databases is absolutely identical.

How does one go about accessing these separate databases from a single SQL Server, and how does one tell the Linq to SQL data classes which database to access?

+1  A: 

Just pass it the connection string to the DataContext constructor.

Example:

var dataContext = new FooDataContext ("SomeConnectionStringDependingOnWhichDataBaseToHit");

Every query that you generate based on that data context will hit the DB pointed on the connection string.

AlbertEin
+1  A: 

All objects in the context are defined using two part names (schema.object) and at runtime you just create the context using a connection string pointing to the right database.

Remus Rusanu
A: 

You can add as many Linq to Sql classes that you need.

mark123
It's correct, but it would lame to add more than one Linq to Sql classes that targets the same schema.
AlbertEin
Yes, you're correct. I missed that part. Apologies.
mark123