views:

146

answers:

1

Hi, 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.

Lets 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 ?
Help in this regard would be appreciated.

Thanks,
Mahesh Velaga.

A: 

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();
}
Christian Hayter
Thanks for the reply .. I am trying to use it :)
Mahesh Velaga

related questions