How to copy a feature dataset from an ArcSDE geodatabase to a file geodatabase


The following example uses IFeatureDataConverter::ConvertFeatureDataset to convert an ArcSDE feature dataset into a feature dataset in the new File Geodatabase.  
To successfully run this script yourself, you must modify the SDE connection information to match that needed to connect to your server. This script assumes that you have already successfully run the "Converting Shapefile to an ArcSDE Geodatabase" sample.

How to use

  1. Modify the code to fit your data.
  2. Paste the code into your VB or VBA Application.
[VBA]
Sub CopyDS()
    ' +++ Set connection properties. Change the properties to match your
    ' +++ server name, instance, user name and password for your SDE database
    Dim pOutSDEPropset As IPropertySet
    Set pOutSDEPropset = New PropertySet
    With pOutSDEPropset
        .SetProperty "Server", "test"
        .SetProperty "Instance", "5151"
        .SetProperty "user", "gdb"
        .SetProperty "password", "gdb"
        .SetProperty "version", "SDE.DEFAULT"
    End With
    
    Dim pInSDEWorkspaceName As IWorkspaceName
    Set pInSDEWorkspaceName = New WorkspaceName
    pInSDEWorkspaceName.ConnectionProperties = pOutSDEPropset
    pInSDEWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory.1"
    
    ' +++ get the name object for the input SDE feature dataset
    Dim pFeatureDatasetName As IFeatureDatasetName
    Set pFeatureDatasetName = New FeatureDatasetName
    
    Dim pSDEDatasetName As IDatasetName
    Set pSDEDatasetName = pFeatureDatasetName
    
    pSDEDatasetName.Name = "USA"
    Set pSDEDatasetName.WorkspaceName = pInSDEWorkspaceName
    
    '' +++ create a new File Geodatabase to copy the feature dataset into
    Dim pOutFileFact As IWorkspaceFactory
    Set pOutFileFact = New FileGDBWorkspaceFactory
    
    Dim pOutFileWorkspaceName As IWorkspaceName
    Set pOutFileWorkspaceName = pOutFileFact.Create("C:\data\", "Usa", Nothing, 0)
    
    ' +++ create a new feature datset name object for the output
    ' +++ feature dataset, call it "USA"
    Dim pOutFileFeatDSName As IFeatureDatasetName
    Set pOutFileFeatDSName = New FeatureDatasetName
    
    Dim pOutFileDSName As IDatasetName
    Set pOutFileDSName = pOutFileFeatDSName
    
    Set pOutFileDSName.WorkspaceName = pOutFileWorkspaceName
    pOutFileDSName.Name = "USA"
    
    ' +++ now do the conversion
    Dim pFdtoFd As IFeatureDataConverter
    Set pFdtoFd = New FeatureDataConverter
    
    pFdtoFd.ConvertFeatureDataset pFeatureDatasetName, pOutFileFeatDSName, Nothing, "", 1000, 0
    
    MsgBox "Conversion complete!"
End Sub