5

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 a transaction. When we first tried this by wrapping code blocks with using(var trans = new TransactionScope()) { ...; trans.Complete(); }, we got an appropriate exception telling us we needed to enable network access for remote transactions. We did so and things began to work the way we expected.

Fast-forward to today. There is a little-used part of our app that also received a TransactionScope treatment. Though transactions work properly in all other parts of our codebase, we discovered today that this seldom used piece is throwing the same “Network Access” exception as before:

Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. http://img101.imageshack.us/img101/5480/msdtcnetworkaccesserror.jpg

Here's the code that causes 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've got any suggestions, they would be appreciated. Let me know if I can explain something more. Thanks in advance!!

Florian
  • 1,019
  • 6
  • 22
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
  • What does the `addCode` method do? – Klaus Byskov Pedersen Mar 12 '10 at 08:43
  • It adds code, newId, and newPOA to the line object. It never makes it to addCode() because of the linq select in the line above. – Byron Sommardahl Mar 12 '10 at 17:05
  • Grasping at straws, but is there anything unusual about DiagCodes? Link to another database? Stored proc that does something funny? Triggers? Also, I like the pattern of using a factory to generate DataContexts, so they are all created from one place in the application. In general, though, I've found TransactionScope to be too flaky. Next time I need an ambient transcation (coming soon in my current app), I'm going to implement it myself. No unpredictable MSDTC dependencies, plus it will need to support Oracle as well as SQL Server. – Cylon Cat Apr 01 '10 at 21:27

0 Answers0