I am using C#, ArcGIS Server 10, MS-SQL Server 2008, and I want to replace an ArcGIS SDE feature class inside of a transaction. After the deletion of the feature class, I have to create a new one with the same name (as a copy of another feature class).
After some research I have implemented the following:
public void deleteFeatureClassInTransactionTest(string featureClassName) {
using (WebObject webObj = new WebObject())
{
// Connect to server
AGSServerConnection agsServerConnection = ConnectServer();
agsServerConnection.Connect();
// Initialize workspace
IWorkspace workspace = GetSdeWorkspace();
webObj.ManageLifetime(workspace);
// Initialize edit workspace
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)workspace;
// Initialize feature workspace
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
// Open feature class
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
webObj.ManageLifetime(featureClass);
// Start transaction
muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMNonVersioned);
workspaceEdit.StartEditOperation();
try
{
// Delete feature class
ESRI.ArcGIS.Geodatabase.IDataset pdataset;
pdataset = (ESRI.ArcGIS.Geodatabase.IDataset)featureClass;
pdataset.Delete();
// ... CREATE THE NEW FEATURE CLASS ...
// Simulate exception
throw new Exception("DEBUG");
// Commit
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
}
catch (System.Exception ex)
{
// Rollback
workspaceEdit.AbortEditOperation();
workspaceEdit.StopEditing(false);
throw ex;
}
finally ..
However, the rollback does not work. The table gets deleted immediately.
How can I make this whole process atomic?