确认并提交事务(Transaction)。
Namespace: Aliyun.OpenServices.OpenTableService
Assembly: Aliyun.OpenServices (in Aliyun.OpenServices.dll) Version: 1.0.5290.21916
Syntax
Parameters
- transactionId
- Type: SystemString
事务(Transaction)ID。
Implements
IOtsCommitTransaction(String)Exceptions
Exception | Condition |
---|---|
ArgumentException | transactionId为空引用或值为空字符串。 |
OtsException | OTS访问返回错误消息。 |
WebException | 由于网络原因请求失败, - 或 - 访问超时。 |
InvalidOperationException | 返回结果解析错误。 |
Remarks
Examples
using System; using System.Linq; using System.Net; using Aliyun.OpenServices.OpenTableService; namespace Aliyun.OpenServices.Samples.OpenTableService { class AsyncBatchModifyDataSample { string endpoint = "http://ots.aliyuncs.com"; string accessId = "<your access id>"; string accessKey = "<your access key>"; OtsClient otsClient; public AsyncBatchModifyDataSample() { otsClient = new OtsClient(endpoint, accessId, accessKey); } public void BatchInsertData(string tableName) { int uid = 1; // 将5条RowPutChange放到列表中 var rowChanges = new List<RowChange>(); for (int i = 0; i < 5; i++) { var rowChange = new RowPutChange(); rowChange.PrimaryKeys["uid"] = uid; rowChange.PrimaryKeys["flag"] = true; rowChange.PrimaryKeys["name"] = "contact " + i.ToString(); rowChange.AttributeColumns["groupid"] = 1; rowChange.AttributeColumns["address"] = "中国某地"; rowChanges.Add(rowChange); } // 开始一个事务 try { var transactionId = otsClient.StartTransaction(tableName, uid); // 开始批量修改数据的异步操作 otsClient.BeginBatchModifyData(tableName, rowChanges, transactionId, BatchModifyDataCallback, transactionId); // 这里进行其他操作 } catch (OtsException ex) { Console.WriteLine("操作失败。OTS异常消息:" + ex.Message); // RequestId和HostId可以在有问题时用于联系客服诊断异常 Console.WriteLine("Request ID: {0}\tHostID: {1}", ex.RequestId, ex.HostId); } catch (WebException ex) { Console.WriteLine("操作失败。网络异常:{0}。请检查Endpoint或网络链接。", ex.Message); } } private void BatchModifyDataCallback(IAsyncResult asyncResult) { try { var transactionId = asyncResult.AsyncState as string; // 操作结束时必须调用EndBatchModifyData方法,否则可能会产生资源泄露 otsClient.EndBatchModifyData(asyncResult); // 需要调用ComitTransaction方法提交数据修改 otsClient.CommitTransaction(transactionId); } catch (OtsException ex) { Console.WriteLine("操作失败。OTS异常消息:" + ex.Message); // RequestId和HostId可以在有问题时用于联系客服诊断异常 Console.WriteLine("Request ID: {0}\tHostID: {1}", ex.RequestId, ex.HostId); } catch (WebException ex) { Console.WriteLine("操作失败。网络异常:{0}。请检查Endpoint或网络链接。", ex.Message); } } } }
See Also