3

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

2 Answers 2

2

Try using a combination of multiple webservices and a servicebus like the right hand tree in the following image:

enter image description here

Please note that this is advanced C# but very maintainable and its low coupled!

Sign up to request clarification or add additional context in comments.

1 Comment

Can you share some links on how to do that, I've never worked with them before
2

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
    }
}

2 Comments

I've read something about pulling the connection string from app.config, and applying that to TableAdapters. That way I could use the same TableAdapter on different databases (all tables in all databases have identical schema's, they just hold different data). Wouldn't that be easier? If yes, how do I do it?
@NDraskovic - thats ok you can go for that but i suggest go with this pattern so that you will able to mainitan code easily....for the diferent database there is differernt providers that you need to maange that you can do with this pattern..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.