Chili.Opf3 Send comments on this topic.
Rollback Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class : Rollback Method




Rolls the current transaction back.

Syntax

Visual Basic (Declaration) 
Public Sub Rollback() 
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
 
instance.Rollback()
C# 
public void Rollback()
Managed Extensions for C++ 
public: void Rollback(); 
C++/CLI 
public:
void Rollback(); 

Exceptions

ExceptionDescription
ExceptionNo transaction active.

Example

The following example shows how to use transaction management.
C#Copy Code
// Creates a new ObjectContext that uses an MsSql Server as storage. 
ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "",  
    "localhost", "application")); 
  
// ... Other code. 
  
// Get an ObjectSet containing all user matching the name. 
// The result is sorted by Name. 
ObjectSet<User> objectSet = context.GetObjectSet<User> 
    ("Name like {0} SortBy Name Asc", "%mith%"); 
  
// Change all names of the user objects. 
foreach(User user in objectSet) 

    user.Name = "new Name"; 

  
// Starts a new Transaction. 
context.StartTransaction(); 
  
try 

    // Deletes the user object from the storage. 
    context.PersistChanges(objectSet); 
  
    // Commit the changes to the storage. 
    context.Commit(); 

catch (Exception ex) 

    // Rolls the changes back. 
    context.Rollback(); 
    Console.WriteLine("Error: " + ex.Message"); 

    

Remarks

Rolls the current transaction on the connected IStorage back. This routine is only supported if the storage implements also the ITransactionStorage interface. You don't get an exception if the storage does not support transactions and you call this routine.

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also