I have helluva time wrapping a pair of transactions in two different databases on the same SQL Server. I initially had problems accessing the DTC network, and I solved it. Now the error that I keep getting is "Communication with the underlying transaction manager failed."
We have some customer profiles in the database, and when these profiles become obsolete, we want to move them to the archive database for storage. It's easy (italics for humor), adding them to the archive database and removing them from the main / live database. I have a DataContext for each database. In the code below, Add is executed, and then an error occurs while deleting when trying to use a second DataContext. I have only been working with LINQ for several months, and I have been looking at articles over the past couple of days. I would like to know that something is wrong with my code or if something is not configured properly with DTC or ???
We work on VMware for my workstation and server. - Workstation - Windows 7 SP1 - Server - this is Windows and SQL Server 2008R2
Routine for "Move":
private int MoveProfileToArchiveDB( int iProfileId ) { int rc = RC.UnknownError; // get new Archive profile object ProfileArchive.ProfileInfo piArchive = new ProfileArchive.ProfileInfo(); // 'Live' DataContext using ( ProfileDataContext dbLive = new ProfileDataContext() ) { // get Live profile ProfileInfo piLive = ProfileInfo.GetProfile( dbLive, iProfileId ); // copy Live data to Archive profile object... including the id ProfileArchive.ProfileInfo.CopyFromLive( piLive, piArchive, true ); } bool bArchiveProfileExists = ProfileArchive.ProfileInfo.ProfileExists( piArchive.id ); // make the move a transaction... using ( TransactionScope ts = new TransactionScope() ) { // Add/Update to Archive db using ( ProfileArchiveDataContext dbArchive = new ProfileArchiveDataContext() ) { // if this profile already exists in the Archive db... if ( bArchiveProfileExists ) { // update the personal profile in Archive db rc = ProfileArchive.ProfileInfo.UpdateProfile( dbArchive, piArchive ); } else { // add this personal profile to the archive db int iArchiveId = 0; piArchive.ArchiveDate = DateTime.Now; rc = ProfileArchive.ProfileInfo.AddProfile( dbArchive, piArchive, ref iArchiveId ); } // if Add/Update was successful... if ( rc == RC.Success ) { // Delete from the Live db using ( ProfileDataContext dbLive = new ProfileDataContext() ) { // delete the personal profile from the Profile DB rc = ProfileInfo.DeleteProfileExecCmd( dbLive, iProfileId ); // *** ERROR HERE *** if ( rc == RC.Success ) { // Transaction End (completed) ts.Complete(); } } } } } return rc; }
NOTES:
- I have several different methods for Delete, and they all work outside of TransactionScope.
- ProfileInfo is the main profile table and is approximately the same for Live and Archive databases.
Any help is much appreciated! Many thanks...
source share