Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Single Application -> Multiple Databases

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David W - 26 Oct 2007 21:53 GMT
We have a setup where we have a single web application, but the user can be
attached to any of a hundred different (identically structured) databases
depending on their login credentials.

Currently we are storing the connection string in Session and in each page's
Page_Init we reset any SqlDataSource's connection string.  This works
reasonably well, though not ideal:
SqlDataSource1.ConnectionString = Session("dbconn")

I would like to start experimenting with creating a full data access layer
using an ObjectDataSource and bound controls.  This is easy enough to set up
after following the tutorials on www.asp.net and I added the DataSet/XSD,
but I do not see a way to set the underlying connection string.  It is
pulling the original connection string from web.config.  I don't see a class
file that I can edit and I can't access the properties of the DAL through
the ObjectDataSource.

Any idea how I can accomplist this?

Thanks.
Mark Rae [MVP] - 26 Oct 2007 22:05 GMT
> We have a setup where we have a single web application, but the user can
> be attached to any of a hundred different (identically structured)
> databases depending on their login credentials.

Any particular reason for this structure, AAMOI...?

> Currently we are storing the connection string in Session and in each
> page's Page_Init we reset any SqlDataSource's connection string.  This
[quoted text clipped - 8 lines]
> don't see a class file that I can edit and I can't access the properties
> of the DAL through the ObjectDataSource.

I guess it would depend on the backend RDBMS. If it's SQL Server, I would go
for the factory pattern described in Microsoft's DAAB:
http://www.dotnetjunkies.com/Article/29EF3A4F-A0C2-4BB2-A215-8F87F100A9F9.dcik

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

David W - 26 Oct 2007 23:03 GMT
>> We have a setup where we have a single web application, but the user can
>> be attached to any of a hundred different (identically structured)
>> databases depending on their login credentials.
>
> Any particular reason for this structure, AAMOI...?

By law (HIPAA), for performace (smaller tables and multiple servers),
management (easier to move around databases to different servers as needed,
backups, restores, etc.), security (separate logins for each database, and
no chance of accidental crossover (easier row level security).  Each
customer has their own database and there is no crossover (other than some
lookup tables that get pushed to every database each release) so it works
out very well in our situation.  There is one base database that stores the
location of each database for each customer.

Yes, its SQL Server 2005 Standard.

I'll look at that appication block, but I don't think that ties in directly
to the DAL from looking at it.

-Dave
Mark Rae [MVP] - 26 Oct 2007 23:26 GMT
> I'll look at that appication block, but I don't think that ties in
> directly to the DAL from looking at it.

That's precisely what it is:
http://msdn.microsoft.com/msdnmag/issues/05/07/DataPoints/

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

sloan - 26 Oct 2007 22:32 GMT
//SqlDataSource1.ConnectionString = Session("dbconn")//

Ahhh......

Just stored the connection string NAME.... as the most recent picked item

{
   ConnectionStringSettingsCollection connectionStrings =
ConfigurationManager.ConnectionStrings;

   ConnectionStringSettings connection;
   foreach ( connection in connectionStrings) {

       string connectionStringName = connection.Name;
       string connectionString = connection.ConnectionString;
       string providerName = connection.ProviderName;

       Debug.Print(connectionStringName);
   }

   this.GridView1.DataSource = connectionStrings;
   this.GridView1.DataBind();
}

Get rid of those stupid "auto generated adapters" (FillTable) things when
you create your Strong DataSet.
Those things are the devil.

You can get something like the EnterpriseLibrary.Data to help if you want.
Either way, write a real DAL object ... which will populate your strong
dataset... and pull the connection string info from the config file, using
the simple NAME passed into your DAL object.

That auto generated stuff is for the birds, esp when you want to pick the
database dynamically.

class ZebraData
{
   public  static ZebraStrongDS GetAllZebras( string connectionStringName ,
string zebraColor )
{
   //pull the connection string from the config file with the objects above
   //
      ZebraStrongDS  returnDS = new ZebraStrongDS ();

   // i threw in zebraColor as a param...
   //call LoadDataSet method here, to populate the returnDS with
resultset(s) from a stored procedure or something

}

}

You can check my blog, I have several NLayered (and now 1 NTiered example)
there:
http://sholliday.spaces.live.com/Blog/

> We have a setup where we have a single web application, but the user can
> be attached to any of a hundred different (identically structured)
[quoted text clipped - 16 lines]
>
> Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.