在VS2003中WebService实现两阶段事务:
using System.EnterpriseServices;
[WebMethod(TransactionOption = TransactionOption.Required)]
public void Process()
{
try
{
ContextUtil.EnableCommit();
..........对数据库的操作
ContextUtil.SetComplete();
}
catch (Exception error)
{
ContextUtil.SetAbort();
..............
}
finally
{
.............
}
}
但是在VS2005却不起事务的作用,也不报错。原来MS在VS2005对事务的实现完全变化了,具体方法如下
using using System.Transactions;
[WebMethod]
public void Process()
{
try
{
CommittableTransaction ts = new CommittableTransaction();
..........对数据库的操作
ts.Commit();
}
catch (Exception error)
{
ts.Rollback();
..............
}
finally
{
.............
}
}