Byr*_*ahl 5 c# msdtc sql-server-2005 transactionscope linq-to-sql
在 Windows Server 2003 上使用 ASP.NET 3.5、Linq to SQL、SQL Server 2005。在 XP SP3 上本地运行 VS 2008。
\n我们需要能够将插入、更新和删除包装在事务中。当我们第一次尝试用 包装代码块时using(var trans = new TransactionScope()) { ...; trans.Complete(); },我们得到了一个适当的异常,告诉我们需要为远程事务启用网络访问。  我们这样做了,事情开始按照我们的预期进行。
快进到今天。我们的应用程序中有一个很少使用的部分也接受了 TransactionScope 处理。尽管事务在代码库的所有其他部分都能正常工作,但我们今天发现这个很少使用的部分抛出了与以前相同的 \xe2\x80\x9cNetwork Access\xe2\x80\x9d 异常:
\n\n这是导致异常的代码:
\nusing (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))\n{\n    using (var dc = new ChargeXferDataContext())\n    {\n        //create \'Line\' object and set initial values\n        Line line = new Line();\n        line.Unit_Num = UnitId;\n        line.SubmittedBy = Viewer.Alias();\n        line.LineSubmittedOn = DateTime.Now;\n\n        //get codes to move from checked rows\n        //iterate rows in current gridview\n        foreach (GridViewRow row in gv.Rows)\n        {\n            //if checked, insert move order\n            HtmlInputCheckBox cb = (HtmlInputCheckBox)row.FindControl("RowLevelCheckBox");\n            if (cb.Checked)\n            {\n                //1st: get required values\n                int id = Convert.ToInt32(((TextBox)row.FindControl("fldCodeId")).Text);\n                int newId = Convert.ToInt32(((DropDownList)row.FindControl("ddlNewId")).SelectedValue);\n                char newPOA = Convert.ToChar(((DropDownList)row.FindControl("ddlPOA")).SelectedValue);\n\n                //2nd: get current diag code from old patient\n                //######## Exception happens here...\n                DiagCode code = dc.DiagCodes.SingleOrDefault(c => c.Id == id);\n                //########\n\n                //3rd: add code to emenline object\n                addCode(line, code, newId, newPOA);\n\n            }\n        }\n        dc.SubmitChanges();\n        trans.Complete();\n    }\n}\n如果您有任何建议,我们将不胜感激。如果我可以解释更多内容,请告诉我。提前致谢!!
\n| 归档时间: | 
 | 
| 查看次数: | 622 次 | 
| 最近记录: |