Search code examples
c#error-handlingconnectionintegration-testingems

How to handle issues with Connections cannot be made(either DB or external systems) when multiple connections are available


I have question regarding handling the multiple connections. These connections can be either DB connection, SOA connection, EMS connection etc.....

Lets say I have 1 database connection where I pull data and I have 2 EMS connections both having different data and independent. The data is sent to EMS and update the status whether the data is successfully sent or not.

1) If the database connection is down or any other issues when we cannot access database 2) Any 1 EMS connection is down, the application should continue processing the other EMS connection. 3) What happens if we are able to send data to EMS, but cannot update the DB status bcos of database issues, what are we suppose to do with all the messages that are in memory and we need to send to EMS. 4) Cannot establish connection to 1 EMS, but the other were are able to establish and therefore the application should process that EMS messages.

These are some of the -ve test cases which I have to handle. Please feel free to let me know if any other issues I have to tackle


Solution

  • Multiple connections to different sources, sounds like a good solution for System.Transactions (if EMS supports this).

    Try something like this, this way all 3 operation eithr succeed or fail as a unit of work.

            try
            {
                using (TransactionScope tran = new TransactionScope())
                {
                    Method1Save(); //DB
                    Method2Save(); //EMS1
                    Method3Save(); //EMS2
                    tran.Complete();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem " + ex.ToString());
            }
    

    If EMS does't support a TransactionScope, then you will have to handle it manaully, probably by putting the transaction on the connection itself and then committing all the transactions once the operations succeed, which means keeping the connections open longer for each data source.