Select to view content in your preferred language

How to create a relationship class in VS2010

720
3
02-07-2012 11:24 AM
MichelleBoivin
Regular Contributor
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.
0 Kudos
3 Replies
AlexanderGray
Honored Contributor
First glance code looks ok, so maybe it is data.  Have you tried doing this not in code?  In ArcCatalog for example, can you manually make the relationship class you want?  If not, then it is something to do with the data, perhaps you will get a better error message.  If you can do it, then the problem is in the code.
0 Kudos
MichelleBoivin
Regular Contributor
Thank you Alexander for looking at the code! I am able to run it in model builder on its own and create it manually. I finally received a response from ESRI yesterday and they said the same thing. The data is registered to the database as well as being versioned, I'm running everything as admin, and I am using an ArcInfo license so everything there seems ok. Regarding the data, in 9.3 we were able to do it there programatically as well but ever since the database upgrade to 10.0 funny things keep happening with automating the geoprocessing tools.....the mystery continues.....
0 Kudos
MichelleBoivin
Regular Contributor
In response to my own post and to let everyone know, there are some defects in 10.0 and 10.1 with respect to a break with the GeoProcessor when running certain processes programtically, especially when it comes to using any models.

A response from ESRI:
"Michelle,
I believe this to be a defect. I have attempted many different avenues to try and solve this issue.
I will be submitting a defect shortly. I do believe this to be an issue at 10.1 as well. I am submitting this in hopes that it can still be remedied.

Regards,
Jamie P."

Since this response he and I have been working on a small subsection of my code for them to test and debug within the development group. If anyone is in need of the situation or status, the Incident # is 1004220.
0 Kudos