<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Change Feature Layer Data Connection Source Directly Through Enterprise GDB in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/change-feature-layer-data-connection-source/m-p/1031233#M6278</link>
    <description>&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;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?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Menu1_button4 : Button
    {
        protected override void OnClick()
        {
            if (MapView.Active?.Map == null) return;
            QueuedTask.Run(() =&amp;gt;
            {

// 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();
            });
        }
    }&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 27 Feb 2021 00:54:30 GMT</pubDate>
    <dc:creator>DerekSalinas</dc:creator>
    <dc:date>2021-02-27T00:54:30Z</dc:date>
    <item>
      <title>Change Feature Layer Data Connection Source Directly Through Enterprise GDB</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/change-feature-layer-data-connection-source/m-p/1031233#M6278</link>
      <description>&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;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?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Menu1_button4 : Button
    {
        protected override void OnClick()
        {
            if (MapView.Active?.Map == null) return;
            QueuedTask.Run(() =&amp;gt;
            {

// 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();
            });
        }
    }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 27 Feb 2021 00:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/change-feature-layer-data-connection-source/m-p/1031233#M6278</guid>
      <dc:creator>DerekSalinas</dc:creator>
      <dc:date>2021-02-27T00:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change Feature Layer Data Connection Source Directly Through Enterprise GDB</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/change-feature-layer-data-connection-source/m-p/1031284#M6282</link>
      <description>&lt;P&gt;What does&amp;nbsp;Geodatabase(dbGdbConnection).GetConnectionString() return?&lt;/P&gt;&lt;P&gt;You can&amp;nbsp;hardwire that connection string and forgo the sde file.&amp;nbsp; If it has a password in it (instead of using OS Auth) it will be encrypted.&amp;nbsp; You &lt;EM&gt;could&lt;/EM&gt; replace the encrypted password with an actual password - but you really shouldn't.&amp;nbsp; Better to use OS Auth.&amp;nbsp;&lt;STRONG&gt; Hardwiring passwords in software is a security hole.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When you create a new layer with a connection from an sde file, then save the layer to an lyrx, the credentials get embedded in the lyrx - there is no dependency on the sde file.&amp;nbsp; Open the lyrx file with notepad and see for yourself.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 15:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/change-feature-layer-data-connection-source/m-p/1031284#M6282</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-02-27T15:05:09Z</dc:date>
    </item>
  </channel>
</rss>

