views:

68

answers:

2

Hi All

I having a slight design problem : I have to create a Web Service (asmx or wcf) that retrieves customer data from multiple database servers, each one is exactly the same except they will contain data for different States (1 DB server per state, big states can have multiples etc).

This will be used by a call center, for example, someone calls the call center and says, can i have an indication when my order will be delivered my order no is "aa_etc" and the service should run a query on all servers and return all the orders details for that order.

This is straight forward, except there is multiple servers to query.My idea is to have central sqlite db with all connection strings of the current online servers and then query each one in turn


public class OnlineServer 
{
 public string Name {get;set;}
 public string ConnectionString {get;set;} 
}
...
public class Order
{
   public List OrderDetail getDetails(string orderno,string connstring)
   {
     //Code to get all orders from database using specified connstring
   }
   ....
}
....

List servers = getOnlineServers();

foreach(OnlineServer in servers)
{
  OrderDetails d = Order.getDetails("aa_etc",OnlineServer.ConnectionString);
}


Just writing down this idea feels totally wrong.

I would really appreciate it if someone can help me get going with this in the right direction, this is a really big project and starting this wrong will just end up in tears later on.

Thanks

+1  A: 

If you cannot some how merge the data in to a single DB. You may be able to use nHibernate. It can query multiple databases see http://mikehadlow.blogspot.com/2008/10/mapping-entities-to-multiple-databases.html

You would have to set up a different entity per server. By doing it this way it would take care of all your DB connections, pooling, sessions etc.

Daveo
It would have been ideal but unfortunately these systems are already split for various reasons including performance.
Gaven
A: 

I want to consider this problem a bit futher but I have an off-the-wall idea which might be of interest so I'll through it out there.

My idea is to have central sqlite db with all connection strings of the current online servers and then query each one in turn

This gave me an idea: why not fire off a search query to each system asynchonously? I'm thinking AJAX here (but you could use iFrames)...

  1. The user enters a search and hits "Go".
  2. Somehow you loop through your collection of known data sources, but each "sub" search is seperate and asynchonous (think federated search).
  3. As results come back they are displayed on screen to the user - who can then stop the search process if they get a match they like.

I'm assuming the data would be "pulled together" visually by the UI - either by straight layout or via clever client-side code - this would give you further options to tailor the UI but at the expense of a more complex client-side code base.

You'd have other options too, like allowing the user to narrow their search by data source if they wanted to.

Also, adding / removing data sources would be simple.

This is where I need to address you're actual question more directly; in my opinion you'd most definately want a seperate service per database - but there's flexibility in how you do that.

  • Having a collection of services that reflects the data sources gives you a clean logical architecture.
  • Doing this doesn't preclude putting something over the top that brings it together (thinking of loose-coupling here).
  • It's always much easier to put stuff together than tear them apart.
  • You'd still be able to re-use code: multiple instances perhaps.
  • You'd have some management overhead due to multiple instances - but also the flexibility to management them better: access control, dedication of resources, etc.
Adrian K
Thanks Adrian - at this stage i am trying to figure out how the service should work, once that is sorted asynchronous responses should not be a problem to add.
Gaven
Sure; I guess I'm suggesting services on each database to expose the data, and then the UI to bring them together. Have I misinterpreted your question?
Adrian K
Hi, well i could add a service per server/db but my idea is to have only one main service. Then the app (web or forms) developer using the service wouldn't need to worry about adding additional references to newly added servers/db's
Gaven
Ahhh - I'd go the other way, I'll update my answer.
Adrian K
Thanks Adrian for you input. So, instead of having a db with the connection strings you suggest i have services in the db? - Remember the end result is 1 service used by a developer not knowing which data sources is involved.
Gaven
Yeah - pretty much; somewhere you'll have information where the data sources are - doesn't matter if they're db-conn strings or service end-points. I'd then wrap all of this into a component that other systems / developers could use with ease. You'll know more about your situation that I do, but based on what you've said I'd have a separate *wrapper* for each data source - just to expose the data programmatically. On top of this you could build a service that rolled it all together. Thinking on it some more the wrapper could simply be some managed code - not necessarily a (WCF) "service".
Adrian K