Quantcast
Channel: Forums - ArcObjects SDKs
Viewing all articles
Browse latest Browse all 1374

IWorkspaceFactory deletes all features in original database

$
0
0
Another fun intermittant problem... I have a system requirement to make a full back-up of a gdb before doing some crunching on it to make sure to be able to back-out if something nasty happens. Turns out the back-up I do is causing something nasty

Code:

    Dim wkspcFact As IWorkspaceFactory = New FileGDBWorkspaceFactory 'I later changed this use activator (no difference)
    Dim copyWsName As IWorkspaceName = Nothing
    wkspcFact.Copy(CType(dsWork.FullName, IWorkspaceName), IO.Path.GetDirectoryName(candidateFullPath), copyWsName)

    Trace.WriteLine("copy workspace done to " & copyWsName.BrowseName)
    Dim copyWkDS As IDataset = DirectCast(DirectCast(copyWsName, IName).Open, IDataset)
    If copyWkDS.CanRename() Then
      copyWkDS.Rename(IO.Path.GetFileName(candidateFullPath))
      Trace.WriteLine("Rename to : " & candidateFullPath)
    End If

The code is called from arcmap during an edit session.
The problem that some times happens is that the copy goes smoothly and the back-up is fine but all the features in the original are gone. Using featurecount on the featureclasses return the correct count but using gp tools report the feature classes as empty as they appear to be in arcmap. Restarting the edit session still reports the original number of features in the feature classes even if they are empty. If I restart ArcMap, the feature count is zero. ArcCatalog also report a feature count of zero.

I replace the above code with this much less elegant code that seems to work better.
Code:

  Dim SourcePath As String = workspace.PathName
    IO.Directory.CreateDirectory(candidateFullPath)
    For Each dirPath As String In IO.Directory.GetDirectories(SourcePath, "*", IO.SearchOption.AllDirectories)
      IO.Directory.CreateDirectory(dirPath.Replace(SourcePath, candidateFullPath))
    Next


    For Each newPath As String In IO.Directory.GetFiles(SourcePath, "*.*", IO.SearchOption.AllDirectories)
      Try
        'if the file has a lock on it, as lock files do, it will fail to copy.
        'the prefered workspace copy is causing bigger problems than this.
        If String.Compare(IO.Path.GetExtension(newPath), ".lock", True) <> 0 Then
          IO.File.Copy(newPath, newPath.Replace(SourcePath, candidateFullPath), True)
        End If
      Catch ex As Exception
        Trace.WriteLine(ex)
        Trace.WriteLine(newPath)
      End Try
    Next


Viewing all articles
Browse latest Browse all 1374

Trending Articles