开发者

Atomicity of Data Adapter in ADO.NET

I am new to ADO.NET and learning it. I was wondering if Data Adapter in ADO.NET provides atomicity or ACID properties by itself when filling the Data Set and updating the Database, or do we have to use transaction explicitly to achieve this.

Let's say:

  • I want to fetch data 开发者_运维技巧from the Database through the Data Adapter to a Data Set
  • Send some information to a website
  • Make some changes to the data in Data Set
  • Update the Database using DataAdapter.Update(DataSet)

I want all the steps (can exclude first step if needed, as it will be a offline data which can be fetched in one go) to be done in one go, atomically, will I need a transaction ? If not how to achieve this?


I have checked the implementation of SqlDataAdapter with Reflector, and it looks to me as if it just executes the relevant commands (InsertCommand, UpdateCommand, DeleteCommand) one after another in sequence without imposing any sort of transaction around them. I suspect all other types of adapter written by Microsoft will work the same way.

If you want atomic updates, you should create your own transaction, e.g.

using(var scope = new TransactionScope()) {
    adapter.Update(dataSet);
    scope.Complete();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜