Update Dataset Transaction

I am using UpdateDataset functionality of Enterprise Library 3.1  for batch updates in a Dataset
.I am having  begin Transaction Commit RollbackTransactions in my Code as shown in
http://msdn.microsoft.com/msdnmag/issues/05/10/DataPoints/  (Save Multiple Rows At Once Figure 5).
Its the same I am using too... Is it that we need to have transaction even in stored Procedure..??? Or is it enough to have it in code as shown by this Microsoft Example...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There is no requirement to put transaction in database if you are using in your & wiseversa.

This code will handle the transactions itself.
dotnet0824Author Commented:
my doubt is that in my stored proc I dont have transactions as I have implemented in code... I DONT HAVE RETURN statements or OUTPUT PARAMETERS (As Batch UPdates doesnot support return parameters or Output Parameters) ....Its clearly given by microsoft. Now if an error occours in stored proc how would the code know that its error occoured
There is no requirement to put transaction in database if you are using in your code & wiseversa.

This code will handle the transactions itself.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

The transaction is associated with the connection. If you start a transaction, invoke a stored procedure, then commit or rollback in the code on that connection, you should not put any transaction code in the stored procedure. You can make multiple calls to the database server, and keep them all in one transaction. That is defeated if you add transaction code in your SPs.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If an error occurs in the stored procedure, an exception should be thrown by the command object. You can deal with the transaction as:
     Invoke stored procedure
     Commit transaction

Catch ex as Exception
     rollback transaction
     Generate error message to pass back to caller, or re-throw the ecxeption

     close the connection
End Try

dotnet0824Author Commented:
an exception should be thrown by the command object
I am using the same code posted in my first message
 http://msdn.microsoft.com/msdnmag/issues/05/10/DataPoints/  (Save Multiple Rows At Once Figure 5).
Should I implement any other than that as per ur statement  (Error should be thrown by Command object, thats not mentioned in the microsoft post)
The following code is from Figure 4 in that page. Note the try - catch. If you attempt an action in a DB, and that action fails, there is an exception throw. It does not matter if it's a stored procedure or not.


public void InsertRegionsAndTerritoriesInTransaction(
    ArrayList territories, ArrayList regions)
    Database db = DatabaseFactory.CreateDatabase();
    IDbConnection connection = db.GetConnection();
    IDbTransaction transaction = connection.BeginTransaction();
        string insertRegionProc = "prInsertRegion";
        foreach(RegionEntity newRegion in regions)
            DBCommandWrapper regionCmd =
            regionCmd.AddInParameter("id", DbType.Int32, newRegion.ID);
                DbType.String, newRegion.Description);
            db.ExecuteNonQuery(regionCmd, transaction);
        string insertTerritoryProc = "prInsertTerritory";
        foreach(TerritoryEntity newTerritory in territories)
            DBCommandWrapper territoryCmd =
            territoryCmd.AddInParameter("id", DbType.Int32,
                DbType.String, newTerritory.Description);
                DbType.Int32, newTerritory.RegionID);
            db.ExecuteNonQuery(territoryCmd, transaction);
        if (connection.State == ConnectionState.Open) connection.Close();

Open in new window

dotnet0824Author Commented:
Thanks  very much
My pleasure. Good luck.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.