Reputation: 706
I'm about to start a pretty large project, so I'm gathering informations about some problems that I predicted while reading project documentation and client requests. One of those problems is this:
My client is a company that has multiple subdivisions, and each of those subdivisions uses its own database. Now, I've my task is to make an administration application that all of those subdivisions will be using (they all perform the same tasks, they are just divided because of their geographical locations and some legal regulations that are not important for my question). So, my problem is how to make an application that will be able to switch between databases. Usually, I could do it by creating a WinForm that would contain fields for input (e.g textBoxes or comboBoxes) where user could choose which connection to use, but I have a problem with this approach because of reports that these applications have to generate. Up until now I've been working with .rdlc reports that use datasets created by TableAdapters. So if I create a dataset programmaticaly, I don't know how to generate a report. But, if I create report based on a TableAdapters dataset, I don't know how to change TableAdapters connection string (except for duplicating TableAdapters so each one uses another connection string but that is not efficient at all). I'm using C# to create WinForms and SQL to work with databases. Please help me with this problem. Thanks
Upvotes: 3
Views: 5914
Reputation: 176896
For this I can suggest you go for Factory Design pattern for object creation this will help you to create proper database object even if you add any no of different database in your application
//factory inerface
public inteface DataBaseCommonFactory()
{
///you all coomon methods are here
public bool createuser();
}
//DAtabase specifc classes
//sql server
public class SqlServer : DataBaseCommonFactory
{
public bool createuser()
{
//implementation
}
}
//oracle server
public class OracleServer : DataBaseCommonFactory
{
public bool createuser()
{
//implementation
}
}
//mysql server
public class MySqlServer : DataBaseCommonFactory
{
public bool createuser()
{
//implementation
}
}
public class DataBaseCreationFactory
{
public DataBaseCreationFactory(string DatabaseType)//this might be enum
{
if(DatabaseType == "Sqlserver")
return new SqlSErver();
if(DatabaseType == "Oracleserver")
return new OracleSErver(); //same for mysql or anyother datavase
}
}
public class Client
{
public void mymethod()
{
DataBaseCommonFactory sqlobject = new DataBaseCreationFactory("Sqlserver")
sqlobject.CreateUser();
//if oracle is ther than parameter is orcalserver - or anyother database
}
}
Upvotes: 2
Reputation: 3575
Try using a combination of multiple webservices and a servicebus like the right hand tree in the following image:
Please note that this is advanced C# but very maintainable and its low coupled!
Upvotes: 2