I use 2 different dlls to connect to 2 database in my project . each dll has it’s own DAL layer .
now in a page I need to insert a set of related data into these 2 databases . I want to use transaction to make sure data are inserted correctly . but as I just have access to public methods of Insert() of each assembly , not the ADO.net codes . how can I handle this situation ? is there anything like this in c# ?
beginTransaction(){
dll1.class.Insert(data);
dll2.className.Insert(relatedData);
....
}
You are looking for the
TransactionScopeclass:Example usage:
As @Anders Abel commented, the servers running the databases involved in the transaction will need the MSDTC service to be running and configured correctly on both the DB servers and the client machines. The DTCPing utility is very helpful in this regard.
As Steve B commented, there is an assumption here that all the databases and the associated drivers support distributed transaction enlistment. Check your documentation…