.NET开发中的事务处理大比拼
2014-11-24 00:51
513 查看
本文转载:http://www.cnblogs.com/jhxk/articles/2696307.html
http://liubaolongg.blog.163.com/blog/static/21386802201222631355218/
.NET事务
ADO.NET事务
View Code
http://liubaolongg.blog.163.com/blog/static/21386802201222631355218/
.NET事务
ADO.NET事务
在方法之前增加属性[AutoComplete(true)],这样如果方法执行时没有异常就默认提交,如果有异常则这个方法就会回滚。 using System; using System.Data.SqlClient; using System.EnterpriseServices;//企业级服务COM+事务 namespace ClassTran { [Transaction(TransactionOption.Required)] public class OrderData2 : ServicedComponent { //自动事务 [AutoComplete(true)] public string WorkTran() { string msg = ""; string conString = "data source=127.0.0.1;database=codematic; user id=sa;password="; SqlConnection myConnection = new SqlConnection(conString); myConnection.Open(); SqlCommand myCommand = new SqlCommand(); myCommand.Connection = myConnection; try { myCommand.CommandText = "update P_Product set Name='电脑2' where Id=52"; myCommand.ExecuteNonQuery(); myCommand.CommandText = "update P_Product set Name='电脑3' where Id=53"; myCommand.ExecuteNonQuery(); msg ="成功!"; } catch (Exception ex) { msg = "失败:"+ex.Message; } finally { myConnection.Close(); } return msg; } } }
View Code
相关文章推荐
- .NET开发中的事务处理大比拼 之 System.Transactions
- .NET开发中的事务处理大比拼 之 ASP.NET页面级别的事务
- .NET开发中的事务处理大比拼 之 SQL和存储过程级别事务
- .NET开发中的事务处理大比拼 之 企业级服务COM+事务
- .NET开发中的事务处理大比拼 之 SQL和存储过程级别事务
- .NET开发中的事务处理大比拼 之 企业级服务COM+事务
- .NET开发中的事务处理大比拼 之 ASP.NET页面级别的事务
- .NET开发中的事务处理大比拼
- .NET开发中的事务处理大比拼 之 企业级服务COM+事务 (转)
- .NET开发中的事务处理大比拼
- .NET开发中的事务处理大比拼 —《.NET深入体验与实战精要》
- .NET开发中的事务处理大比拼 之 ADO.NET级别的事务
- .NET开发中的事务处理大比拼
- .NET开发中的事务处理大比拼 之 ADO.NET级别的事务
- .NET开发中的事务处理大比拼 之 System.Transactions
- .NET开发中的事务处理大比拼
- .NET开发中的事务处理
- .NET开发中的事务处理
- NET开发中的事务处理大比拼
- .NET的事务处理