How to create a relationship class in VS2010

Discussion created by mbalxnder on Feb 7, 2012
Latest reply on Mar 27, 2012 by mbalxnder
The following is code I have put together to create a relationship class between CAD_PARCELS which is a feature class and PDATA which is a SQL table registered with both the geodatabase and SDE. At first I would get through the originClass and destinationClass and it would fail on the CreateRealtionshipClass giving an unknown RunTime Error. Now (after minor mods) it fails on defining the destinationClass stating that PDATA is not defined. PDATA has an OID field that is recognized and indexed in Catalog. Need help please....


Private Function CreateRelationshipClass()

        Dim serverName As String = "GS002"
        Dim sdeWrkSp As IWorkspaceFactory2 = New SdeWorkspaceFactory
        Dim connProps As IPropertySet = New PropertySet
        With connProps
            .SetProperty("SERVER", serverName)  ' Server name
            .SetProperty("INSTANCE", "sde:sqlserver:" + serverName) ' Instance
            .SetProperty("DATABASE", "cfwgis") ' Database name
            .SetProperty("USER", "sde") ' User ID
            .SetProperty("PASSWORD", SDE_PASSWORD) ' Password
            .SetProperty("VERSION", "sde.DEFAULT") ' Version
        End With

        Dim wrk As IFeatureWorkspace = sdeWrkSp.Open(connProps, 0)

        'Open the participating classes from the workspace.

        Dim originClass As IFeatureClass = wrk.OpenFeatureClass("CFWGIS.SDE.CAD_PARCELS")
        Dim destinationClass As IObjectClass = wrk.OpenTable("CFWGIS.SDE.PDATA")

        'Create the Relationship Class
        Dim relclass As IRelationshipClass2 = wrk.CreateRelationshipClass("CFWGIS.SDE.RC_P_PDATA", originClass, destinationClass, _
                                                                          "PDATA", "CAD_PARCELS", esriRelCardinality.esriRelCardinalityOneToOne, _
                                                                          esriRelNotification.esriRelNotificationNone, True, False, Nothing, "TAXPIN", "", "GIS_LINK", "")

    End Function

According to everything I have seen on the forums and Help, etc this should work, but I can't seem to get past the "feature not defined" issue.