Good Afternoon,
So I currently have a button that adds a FeatureLayer to my map and redirects the .lyr data source to a featureclass via an SDE connection file. I would like to be able to redirect the data source directly to the Enterprise GDB since i have the necessary login credentials. What would i have to change in the example below to include the login credentials and server name to the connection info?
internal class Menu1_button4 : Button
{
protected override void OnClick()
{
if (MapView.Active?.Map == null) return;
QueuedTask.Run(() =>
{
// add lyr/lyrx to map: This portion contains the Symbology of the added FeatureClass
var featureLayer = (FeatureLayer)LayerFactory.Instance.CreateLayer(new Uri(@"FeatureLayer File"), MapView.Active.Map, 0, "Displayed Name");
CIMDataConnection currentDataConnection = featureLayer.GetDataConnection();
CIMStandardDataConnection updatedDataConnection = null;
WorkspaceFactory wf = WorkspaceFactory.SDE;
var dbGdbConnection = new DatabaseConnectionFile(new Uri(@"sde connection file path"));
// provide a replacement data connection method
updatedDataConnection = new CIMStandardDataConnection()
{
WorkspaceConnectionString = new Geodatabase(dbGdbConnection).GetConnectionString(),
WorkspaceFactory = wf,
Dataset = "Exact FeatureClass",
DatasetType = esriDatasetType.esriDTFeatureClass
};
featureLayer.SetDataConnection(updatedDataConnection);
featureLayer.ClearDisplayCache();
});
}
}