TransactionScope 分布式事务
? /// 發(fā)送消息
???????? ///</summary>
??????? ///<param name="sendUserId"></param>
??????? ///<param name="toUser">格式7FFA3AF2-E74B-4174-8403-5010C53E49A7|userName,7FFA3AF2-E74B-4174-8403-5010C53E49A7|userName</param>
??????? ///<param name="content"></param>
??????? ///<param name="sendedStatus">表示已送</param>
??????? ///<returns></returns>
??????? publicstaticint sendMessage(string sendUserId, string toUser, string content, string sendedStatus)
??????? {??????????
??????????? int receiveCount =0;
??????????? TransactionOptions transactionOption =new TransactionOptions();
??????????? //設(shè)置事務(wù)隔離級(jí)別
??????????? transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
??????????? // 設(shè)置事務(wù)超時(shí)時(shí)間為60秒
??????????? transactionOption.Timeout =new TimeSpan(0, 0, 60);
??????????? using (TransactionScope scope =new TransactionScope(TransactionScopeOption.Required, transactionOption))
??????????? {
??????????????? try
??????????????? {
??????????????????? //在這里實(shí)現(xiàn)事務(wù)性工作
???? //發(fā)送消息
??????????????????? insertMessage(sendUserId, toUser, content, sendedStatus);
???? //在接收信息表中插入記錄
??????????????????? receiveCount += insertReceiveMessage(userids[0], sendUserId, content, "0");
??????????????????
??????????????????? // 沒(méi)有錯(cuò)誤,提交事務(wù)
??????????????????? scope.Complete();
??????????????? }
??????????????? catch (Exception ex) {
??????????????????? thrownew Exception("發(fā)送信息異常,原因:"+ex.Message);
??????????????? }finally{
??????????????????? //釋放資源
??????????????????? scope.Dispose();
????????????????? }??????????????????????????????
??????????? }
??????????? return receiveCount;
??????? }
轉(zhuǎn)載于:https://www.cnblogs.com/fx2008/archive/2013/01/30/2882703.html
總結(jié)
以上是生活随笔為你收集整理的TransactionScope 分布式事务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: PHFRefreshControl
- 下一篇: RHEL5.4在线调整磁盘分区大小