ah1508

Trouble Importing Schema to Personal Geodatabase

Discussion created by ah1508 on May 17, 2012
Latest reply on May 18, 2012 by ah1508
I have an Add-In written in VB in Visual Studio 2008.  It works just fine, in that environment.  I recently upgraded it to Visual Studio 2010 (on a different machine), recompiled and now I get an error at
 conflictsFound = gdbXmlImport.GenerateNameMapping(gXML, WS, enumNameMapping)

I tried bringing the original compiled Add-In in on the new computer and running it, but it gets the same error (among others).  The new computer is running service pack 3, but I think that is the only other difference.  Does anyone have any clue as to why it will run on one but not the other?

[ATTACH=CONFIG]14409[/ATTACH]

Here's all the code:
   Public Function CreateAccessWorkspace(ByVal Path As String) As IWorkspace
        ' Instantiate an Access workspace factory and create a personal geodatabase.
        ' The Create method returns a workspace name object.
        Dim gp As IGeoProcessor2 = New GeoProcessor
        Dim pParArray As IVariantArray = New ESRI.ArcGIS.esriSystem.VarArray
        pParArray.Add(Path)
        pParArray.Add(gPGDB)
        pParArray.Add("9.2")
        gp.AddOutputsToMap = False
        gp.OverwriteOutput = True
        Dim Result As IGeoProcessorResult2
        Result = gp.Execute("CreatePersonalGDB_management", pParArray, Nothing)
        Dim WS As IWorkspace
        Import_Schema(WS, Path)

 End Function

    Public Sub Import_Schema(ByRef WS As IWorkspace, path As String)
        Try
            Dim WSF As IWorkspaceFactory2 = New AccessWorkspaceFactory
            MessageBox.Show(Path & gPGDB)
            WS = WSF.OpenFromFile(path & gPGDB, 0)

           
            Dim WSE As IWorkspaceEdit2 = WS
             ' Create a GdbImporter and use it to generate name mappings.
            Dim gdbXmlImport As IGdbXmlImport = New GdbImporter()
            Dim enumNameMapping As IEnumNameMapping = Nothing
            Dim conflictsFound As Boolean
            Try
                conflictsFound = gdbXmlImport.GenerateNameMapping(gXML, WS, enumNameMapping)
            Catch ex As Exception
                MessageBox.Show(ex.ToString, ex.Message)
            End Try

            ' Check for conflicts.
            Dim workspaceDataset As IDataset = CType(WS, IDataset)
            Dim workspaceName As IName = workspaceDataset.FullName
            If conflictsFound Then
                ' Iterate through each name mapping.
                enumNameMapping.Reset()
                Dim nameMapping As INameMapping = enumNameMapping.Next()
                While Not nameMapping Is Nothing
                    ' Resolve the mapping's conflict (if there is one).
                    If nameMapping.NameConflicts Then
                        nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName)
                    End If

                    ' See if the mapping's children have conflicts.
                    Dim childEnumNameMapping As IEnumNameMapping = nameMapping.Children
                    If Not childEnumNameMapping Is Nothing Then
                        childEnumNameMapping.Reset()

                        ' Iterate through each child mapping.
                        Dim childNameMapping As INameMapping = childEnumNameMapping.Next()
                        While Not childNameMapping Is Nothing
                            If childNameMapping.NameConflicts Then
                                childNameMapping.TargetName = childNameMapping.GetSuggestedName(workspaceName)
                            End If
                            childNameMapping = childEnumNameMapping.Next()
                        End While
                    End If
                    nameMapping = enumNameMapping.Next()
                End While
            End If

            ' Import the workspace document, including both schema and data.
            gdbXmlImport.ImportWorkspace(gXML, enumNameMapping, WS, False)

            workspaceDataset = Nothing
            workspaceName = Nothing
            gdbXmlImport = Nothing
            enumNameMapping = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.ToString, ex.Message)
        End Try
    End Sub

Attachments

Outcomes