views:

173

answers:

2

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.

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!!

A: 

The error says it all. Enable the Distributed Transaction Coordinator for network access on your database server.

klausbyskov
As stated, this has been done and transactions are working fine in other parts of the code.
Byron Sommardahl
@Byron Sommardahl, you say it works in other parts of the code? Does it work with that linq2sql datacontext in those places? How come you are not using a connectionstring when new'ing up the datacontext? Are your sure your settings file contains the right connection string and that it DTC is enabled on that machine? Does your database server have a firewall, and have you tried turning it off?
klausbyskov
One DataContext to rule them all. One connection string in ther web.config for the entire app. The same DataContext works everywhere else in the code. The issue is not the database (it was at first, but now that's fixed).
Byron Sommardahl
A: 

I never found a solution to this. Moved on with life.

Byron Sommardahl