Using multiple databases in one application

I am going to start a rather large project, so I am collecting information about some of the problems that I predicted when reading project documentation and client requests. One of these issues is this:

My client is a company with several divisions, and each of these divisions uses its own database. Now I have a task to make an administration application that all these units will use (they all perform the same tasks, they are simply divided due to their geographical locations and some legal norms that are not important for my question), So, my the problem is how to create an application that can switch between databases. Normally I could do this by creating a WinForm that will contain input fields (e.g. textBoxes or comboBoxes) where the user can choose which connection to use, but I have a problem with this approach due to the reports that these applications should generate . So far I have been working with .rdlc reports,which use datasets created by TableAdapters. Therefore, if I create a data set programmatically, I do not know how to create a report. But, if I create a report based on the TableAdapters dataset, I don’t know how to change the TableAdapters connection string (except for duplicating TableAdapters, so everyone uses a different connection string, but this is inefficient at all). I use C # to create WinForms and SQL for working with databases. Please help me with this problem. Thanksbut it is ineffective at all). I use C # to create WinForms and SQL for working with databases. Please help me with this problem. Thanksbut it is ineffective at all). I use C # to create WinForms and SQL for working with databases. Please help me with this problem. Thanks

+3
source share
2 answers

Try using a combination of several web services and a service bus, such as a right-hand tree, in the following image:

enter image description here

Please note that this is advanced C #, but very easy to maintain and low connection!

+1
source

To do this, I can suggest you go to the Factory design pattern for creating an object, this will help you create the correct database object, even if you add no other database to the 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
    }
}
+2
source

All Articles