TransactionScope works in some places, not in others.

Using ASP.NET 3.5, Linq to SQL, SQL Server 2005 on Windows Server 2003. Running VS 2008 on XP SP3 locally.

We need to be able to wrap inserts, updates, and deletes in transactions. When we first tried this, wrapping code blocks with using(var trans = new TransactionScope()) { ...; trans.Complete(); } using(var trans = new TransactionScope()) { ...; trans.Complete(); } using(var trans = new TransactionScope()) { ...; trans.Complete(); } , we received the corresponding exception, telling us that we need to enable network access for remote transactions. We did this , and everything began to work as we expected.

Fast Forward There is a small part of our application that also received TransactionScope processing. Despite the fact that transactions work correctly in all other parts of our code base, we found today that this rarely used piece throws the same "Network Access" exception as before:

Network Access for Distributed Transaction Manager (MSDTC) is disabled. Enable DTC to access the network in the security configuration for MSDTC using the component services administration tool. http://img101.imageshack.us/img101/5480/msdtcnetworkaccesserror.jpg

Here is the code that throws the exception:

  using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue)) { using (var dc = new ChargeXferDataContext()) { //create 'Line' object and set initial values Line line = new Line(); line.Unit_Num = UnitId; line.SubmittedBy = Viewer.Alias(); line.LineSubmittedOn = DateTime.Now; //get codes to move from checked rows //iterate rows in current gridview foreach (GridViewRow row in gv.Rows) { //if checked, insert move order HtmlInputCheckBox cb = (HtmlInputCheckBox)row.FindControl("RowLevelCheckBox"); if (cb.Checked) { //1st: get required values int id = Convert.ToInt32(((TextBox)row.FindControl("fldCodeId")).Text); int newId = Convert.ToInt32(((DropDownList)row.FindControl("ddlNewId")).SelectedValue); char newPOA = Convert.ToChar(((DropDownList)row.FindControl("ddlPOA")).SelectedValue); //2nd: get current diag code from old patient //######## Exception happens here... DiagCode code = dc.DiagCodes.SingleOrDefault(c => c.Id == id); //######## //3rd: add code to emenline object addCode(line, code, newId, newPOA); } } dc.SubmitChanges(); trans.Complete(); } } 

If you have any suggestions, they will be appreciated. Let me know if I can explain anything else. Thanks in advance!

+4
source share
2 answers

I have not found a solution. Continued with life.

+1
source

The error says it all. Enable the distributed transaction coordinator to access the network on the database server.

-1
source

Source: https://habr.com/ru/post/1303825/


All Articles