Cannot Delete Version

3405
3
Jump to solution
05-31-2013 09:22 AM
BrianBehling
New Contributor III
When I try to delete a version, even after stopping the edit operations, ArcObjects is telling the version is in use and it wont delete it.

I tried setting all objects that are referenced by the version object to and calling the garbage collector like in this post

http://forums.esri.com/Thread.asp?c=93&f=993&t=81960

but that doest work. Also tried setting the version access to public, still no go. Even tried tried creating another object derviced from a versionedWorkspace, still nothing.

Also checked for locks, and there are no locks on this version.

Any one else have success deleting a dynamically created version? Wondering if this is a bug.


Random random = new Random();
string versionNum = random.Next(0, 1000000000).ToString();

IVersion targetVersion = (IVersion)sdeWorkspace;
IVersion newVersion = targetVersion.CreateVersion(versionNum);

//IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)newVersion;

IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)newVersion;
IVersionEdit4 versionEdit = (IVersionEdit4)workspaceEdit;
               
//muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();

//Do some edits

versionEdit.Reconcile4(targetVersion.VersionName, true, false, false, false);
versionEdit.Post(targetVersion.VersionName);

workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);

targetVersion = null;
workspaceEdit = null;
versionEdit = null;
GC.Collect();

IEnumLockInfo test = newVersion.VersionLocks;
ILockInfo test2 = null;

while((test2 = test.Next()) != null)
{
    //no locks present
}

newVersion.Delete(); //ArcObjects says version is in use
0 Kudos
1 Solution

Accepted Solutions
BrianBehling
New Contributor III
FYI, Got this to work by destroying all object references to the SDE workspace, calling the garbage collector, creating a new SDE workspace, finding the temporary version created, then deleting it.

There really needs to be a special SDE workspace interface with a disconnect() method.


Marshal.ReleaseComObject(sdeWorkspace);
sdeWorkspace = null;

//remove any other references to the workspace such as tables or cursors

GC.Collect();

IWorkspace deleteVersionWorkspace = openSDE();
IVersionedWorkspace versionedWorkspace = (IVersionedWorkspace)deleteVersionWorkspace;

IVersion versionDelete = versionedWorkspace.FindVersion(versionNum);
versionDelete.Delete();

View solution in original post

0 Kudos
3 Replies
BrianBehling
New Contributor III
FYI, Got this to work by destroying all object references to the SDE workspace, calling the garbage collector, creating a new SDE workspace, finding the temporary version created, then deleting it.

There really needs to be a special SDE workspace interface with a disconnect() method.


Marshal.ReleaseComObject(sdeWorkspace);
sdeWorkspace = null;

//remove any other references to the workspace such as tables or cursors

GC.Collect();

IWorkspace deleteVersionWorkspace = openSDE();
IVersionedWorkspace versionedWorkspace = (IVersionedWorkspace)deleteVersionWorkspace;

IVersion versionDelete = versionedWorkspace.FindVersion(versionNum);
versionDelete.Delete();
0 Kudos
by Anonymous User
Not applicable
Are you using any edit feature events like OnCreate, change or delete etc?
In the past ive seen the rcw for the returned feature from these events hanging around long after the associated com object has been disposed and its the rcw that's holding the lock on the temporary version. There isn't an easy solution for this given the com interop architecture.
I agree, a special method would be nice.
0 Kudos
BrianBehling
New Contributor III
Negative, no edit events being used.
0 Kudos