[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Update Dataset Transaction

Posted on 2007-11-17
9
Medium Priority
?
843 Views
Last Modified: 2011-04-14
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...
0
Comment
Question by:dotnet0824
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 5

Assisted Solution

by:pavaneeshkumar
pavaneeshkumar earned 300 total points
ID: 20303885
There is no requirement to put transaction in database if you are using in your & wiseversa.

This code will handle the transactions itself.
0
 

Author Comment

by:dotnet0824
ID: 20303903
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
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20303907
There is no requirement to put transaction in database if you are using in your code & wiseversa.

This code will handle the transactions itself.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 22

Accepted Solution

by:
JimBrandley earned 700 total points
ID: 20304786
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.

Jim
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20304834
If an error occurs in the stored procedure, an exception should be thrown by the command object. You can deal with the transaction as:
Try
     Invoke stored procedure
     Commit transaction

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

Finally
     close the connection
End Try

Jim
 
0
 

Author Comment

by:dotnet0824
ID: 20305132
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)
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20305282
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.

Jim


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

Open in new window

0
 

Author Comment

by:dotnet0824
ID: 20305657
Thanks  very much
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20305701
My pleasure. Good luck.

Jim
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question