0

I have a question about exporting an (versioned) featureclass stored in a ArcSDE geodatabase to a shapefile with VB.Net. I've created the code which I think should work fine, but ArcObjects "says no", accompanied with the message that the sourcefile (the ArcSDE featureclass) could not be found.

As said I have an featureclass in an ArcSDE database and I want this to export to an shapefile for local use. Previously I used the IExportOperation.ExportFeatureClass method for this operations, but due to limitations of this method I want to rewrite this. Following the ESRI documentation the next best thing is featurclass to featureclass or Copyfeatureclass.

The main goal of the source code is:

  • Async, not the geoprocessors itself, but there are several tasks which use the procedure. The problem does even exist with a single task (the others are turned off for debugging purposes). Each task has its own workspace

  • A local copy of the ArcSDE featureclass

Both Geoprocessors need an path to the sourcefeatureclass and target shapefile. The target is not a problem (it's local, so easy to retrieve), but the devil is in the source. How do I connect the Geoprocessor to the versioned featureclass in the ArcSDE.

The documentation said I should create an SDE Connection file, so I did.

Public Shared Function createSDEConnectionFile(Location As String, SDEFileName As String, ServerName As String, DabaseName As String, ServiceName As String, _
                                             UserName As String, Pwd As String, VersionName As String) As String

        Dim GP As IGeoProcessor2 = New GeoProcessor
        Dim parameters As IVariantArray = New VarArray
        If Not SDEFileName.EndsWith(".sde") Then SDEFileName += ".sde"
        If File.Exists(Location & SDEFileName) Then File.Delete(Location & SDEFileName)


        parameters.Add(Location)  'folderName
        parameters.Add(SDEFileName) 'FileName
        parameters.Add(ServerName) 'serverName
        parameters.Add(ServiceName) 'serviceName
        parameters.Add(DabaseName) 'databaseName 
        parameters.Add("DATABASE_AUTH") 'authType
        parameters.Add(UserName) 'username
        parameters.Add(Pwd) 'password 
        parameters.Add("SAVE_USERNAME")
        parameters.Add(VersionName) 'versionName
        parameters.Add("SAVE_VERSION") 'saveVersionInfo

        Dim result As IGeoProcessorResult2 = Nothing

        Try
            result = GP.Execute("CreateArcSDEConnectionFile_management", parameters, Nothing)
            Dim conn_file As String = result.GetOutput(0).GetAsText()
            Return conn_file
        Catch ex As Exception
            Throw ex
        End Try
    End Function

And I used this file to create the workspace for the Geoprocessor, as explained by the ESRI documentation

Public Shared Sub DBFC2FC(ByVal SourceName As String, ByVal TargetName As String, ByVal TargetLocation As String, ByVal OutputM As Boolean, ByVal OutputZ As Boolean, ByVal SDEFile As String)
        Dim GP As IGeoProcessor2 = New GeoProcessor
        Dim gpParams As IVariantArray = New VarArray
        Dim ZFlag As String = "DISABLED"
        Dim MFlag As String = "DISABLED"
        Dim TargetPath As String

        Try
            GP.ResetEnvironments()
            GP.SetEnvironmentValue("workspace", SDEFile)
            TargetPath = DOTNETLib.Win32Api.GetLongPath(DOTNETLib.Win32Api.DirectoryFormat(TargetLocation))
            If Not TargetName.EndsWith(".shp") Then TargetName += ".shp"

            If OutputM Then MFlag = "ENABLED"
            If OutputZ Then ZFlag = "ENABLED"

            GP.SetEnvironmentValue("OutputZFlag", ZFlag)
            GP.SetEnvironmentValue("OutputMFlag", MFlag)
            gpParams.Add(SourceName) ' in
            gpParams.Add(UCase(TargetPath)) ' outpath
            gpParams.Add(TargetName) ' outname
            gpParams.Add("") ' whereClause

            GP.AddOutputsToMap = False
            GP.Execute("FeatureClassToFeatureClass_conversion", gpParams, Nothing)

        Catch ex As Exception
            Throw
        Finally
            ReleaseComObject(gpParams)
            ReleaseComObject(GP)
        End Try
    End Sub

And here I 'm stuck. I end up in the catch of the method, and the GP.getmessage(3) gives me the following feedback: ERROR 000732: Input Features: Dataset part1Name.part2Name_Part3Name does not exist or is not supported.

However the mentioned Dataset does exist and can be opened with the created .SDE file when used in ArcCatalog.

I would be very happy if somebody could point me at my error or if someone could tell me a better solution.

-1

I found the problem. The creation of the *.sde file works with an ArcSDE connection. But when you use an direct Connect on your server, the property "serviceName"is filled with a wrong value (like: "sde:oracle10g" instead of an instance, like "5152"). At least the Geoprocessor does not accept this.

parameters.Add(ServiceName) 'serviceName

When I switch to an other database with no Direct connect, the code works fine. So when direct connect is used, another solution is required and use the CreateDatabaseConnection_management geoprocessor instead of the CreateArcSDEConnectionFile_management.

See for the documentation here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.