Open SDE Geodatabase with WorkspaceConnectionString

1089
4
07-27-2021 04:33 AM
Zoggo
by
New Contributor III

I have a WorkspaceConnectionString from CIMFeatureDatasetDataConnection looking like that:

Zoggo_0-1627385415861.png

 

With this ConnectionString I like to open a Enterprise Geodatabase (SDE):

GDB = new Geodatabase(new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)

What is the best way to do this?

 

 

 

0 Kudos
4 Replies
Aashis
by Esri Contributor
Esri Contributor

@Zoggo, The Pro SDK doesn’t have a method to open/connect the geodatabase from a workspace connection string. I am curious to know why you use CIMFeatureDatasetDataConnection. Can you use FeatureLayer.GetFeatureClass().GetDatastore() as Geodatabase instead? 

0 Kudos
Zoggo
by
New Contributor III

I'm working with a linear referencing layer (Route Feature Layer). The event table is in a filegeodatabase and the route features is in a enterprise geodatabase. If I use FeatureLayer.GetFeatureClass().GetDatastore() as Geodatabase I only get the  filegeodatabase workspace from the table but I need the enterprise geodatabase workspace from the route features.

0 Kudos
Aashis
by Esri Contributor
Esri Contributor

@Zoggo , A workaround to access the route feature class’s geodatabase from route event layer

      // Get all layers from the map
      IReadOnlyList<Layer> layers = MapView.Active.Map.GetLayersAsFlattenedList();
      
      // Assuming route event layer is the first layer of map
      CIMRouteEventDataConnection connection = layers[0].GetDataConnection() as CIMRouteEventDataConnection;
      
      // Get connection to the route feature class
      CIMDataConnection routeFeatureClassConnection = connection.RouteFeatureClass ;
      
      // Create a feature layer using the route feature class connection
      FeatureLayer featureLayer = LayerFactory.Instance.CreateLayer(routeFeatureClassConnection, MapView.Active.Map, layerName: "RouteFeatureClass" ) as FeatureLayer;
      
      // Use feature layer to access the geodatabase
      Geodatabase geodatabase = featureLayer.GetFeatureClass().GetDatastore() as Geodatabase;

 

0 Kudos
Zoggo
by
New Contributor III

Basically it works. But the solution isn't nice. Because it adds the FeatureClass to the map. That's not wanted and very slow. Is there no other way without adding the layer to the map?

0 Kudos