我正在尝试在从数据库中读取数据时更新数据,请参阅下文.
但在整个事情结束后,数据没有得到更新.
但在整个事情结束后,数据没有得到更新.
是否需要指定任何事务语法?
(当我调试时,我可以看到我检索到了正确的记录.)
这是我的程序:
@H_403_6@SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE MyProcedure @Count int = 100 AS BEGIN SELECT TOP (@Count ) t1.id AS ID,t1.name AS Name,t2.type AS TYPE FROM sampleTable1 as t1 with (nolock),sampleTable2 as t2 with (nolock) WHERE (t1.t2Id = t2.Id) ORDER BY t1.name asc END GO如果我将所有代码放在TransactionScope块中
@H_403_6@using (TransactionScope scope = new TransactionScope()) { // all the C# code above scope.Complete(); }我将得到一个例外“服务器上的MSDTC’localhost-sqlserver2005’不可用.”
如果我只放了一些代码,没有例外,但数据确实没有更新
@H_403_6@using (TransactionScope scope = new TransactionScope()) { sampleTable1 table1 = context.sampleTable1s.SingleOrDefault(t=> t.id = c.ID); table1.isRead = 1; context.SubmitChanges(); scope.Complete(); }谢谢.