Distinguished Contributor
136 Posts
5 Kudos
Registered: ‎07-24-2009
Post 1 of 2

Can you commit a Transaction within a Transaction?

188 Views, 1 Replies
08-15-2012 01:01 PM

Transactions -- Can you commit a Transaction within a Transaction without any problems? 


I have one transaction that cycles through all objects in drawing..

I have another transaction that purges all purgable objects. 


Can I call the Purge Function if I've already started a transaction? 

What's the proper protocol here? Does that make sense? 


  'Purge Database
        Dim count As Integer = PurgeDatabase(DatabaseIn)
        Debug.Print("Number of Items Purged: " & count)

        'Level 1 Start(Transaction/Drawing Database)-----------------------------------------------
        Using myTrans As Transaction = DatabaseIn.TransactionManager.StartTransaction 'Read Drawing Database

            'Level 2 Block Table------------------------------------------------------------
            Dim myBT As BlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead) 'Read BlockTable
            'Loop Through All Objects
            For Each myObjID As ObjectId In myBT 'Changed this line of code from myModelSpace


Private Function PurgeDatabase(ByVal DB As Database) As Integer
        Debug.Assert(DB IsNot Nothing, "DB is nothing.")

        Dim idCount As Integer = 0

        Dim tr As Transaction = DB.TransactionManager.StartTransaction

        Using tr
            'Create the list of objects to "purge"


ADN Support Specialist
433 Posts
67 Kudos
Registered: ‎05-22-2006
Post 2 of 2

Re: Can you commit a Transaction within a Transaction?

08-15-2012 01:34 PM in reply to: VB_Autocad_guy

In general, yes. You can use nested transactions and commit the inner transaction first. If you abort any transaction it should also roll back the committed transactions nested within it. The full operation will only be committed once the topmost transaction has been commited.


Stephen Preston
Autodesk Developer Network
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!