<?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 Access SDE from Data Store in python toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1487902#M70766</link>
    <description>&lt;P&gt;I have a toolbox that accesses a database through an SDE, which is stored locally. This works for local jobs, but I need to deploy this to an Enterprise portal. I've created a Data Store for the SDE, but I can't figure out how to now access the Data Store version of the SDE in a python toolbox. I can find the Data Store through gis.content.search(query='*',item_type="Data Store"). But how do I use it to access a GDB in the SDE?&lt;/P&gt;&lt;P&gt;I need to convert something like:&lt;/P&gt;&lt;P&gt;r'E:\ProProjects\my_project\SDE_connections\my_sde.sde\my_gdb'&lt;/P&gt;&lt;P&gt;To access the same SDE through the Data Store&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jun 2024 17:26:54 GMT</pubDate>
    <dc:creator>sbrowneotogo</dc:creator>
    <dc:date>2024-06-09T17:26:54Z</dc:date>
    <item>
      <title>Access SDE from Data Store in python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1487902#M70766</link>
      <description>&lt;P&gt;I have a toolbox that accesses a database through an SDE, which is stored locally. This works for local jobs, but I need to deploy this to an Enterprise portal. I've created a Data Store for the SDE, but I can't figure out how to now access the Data Store version of the SDE in a python toolbox. I can find the Data Store through gis.content.search(query='*',item_type="Data Store"). But how do I use it to access a GDB in the SDE?&lt;/P&gt;&lt;P&gt;I need to convert something like:&lt;/P&gt;&lt;P&gt;r'E:\ProProjects\my_project\SDE_connections\my_sde.sde\my_gdb'&lt;/P&gt;&lt;P&gt;To access the same SDE through the Data Store&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2024 17:26:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1487902#M70766</guid>
      <dc:creator>sbrowneotogo</dc:creator>
      <dc:date>2024-06-09T17:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Access SDE from Data Store in python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1490951#M70802</link>
      <description>&lt;P&gt;Maybe with ArcGIS API? Untested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcgis.gis import GIS
import os

def main():
    # Get parameters 
    portal_url = arcpy.GetParameterAsText(0)
    username = arcpy.GetParameterAsText(1)
    password = arcpy.GetParameterAsText(2)
    data_store_title = arcpy.GetParameterAsText(3)

    # Authenticate with the Enterprise portal
    gis = GIS(portal_url, username, password)

    # Search for the Data Store item
    data_store_items = gis.content.search(query='*', item_type="Data Store")

    # Find the specific Data Store by title
    data_store = next((item for item in data_store_items if item.title == data_store_title), None)

    if data_store is None:
        arcpy.AddError(f"Data Store with title '{data_store_title}' not found.")
        return

    # Get the connection properties
    connection_properties = data_store.properties.connectionString

    # Use arcpy to access the geodatabase
    arcpy.env.workspace = connection_properties

    # Example: List all feature classes in the geodatabase
    feature_classes = arcpy.ListFeatureClasses()
    arcpy.AddMessage(f"Feature Classes: {feature_classes}")

if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 19:47:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1490951#M70802</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-06-12T19:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Access SDE from Data Store in python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1491775#M70813</link>
      <description>&lt;P&gt;Thanks for the suggestion. I'm able to get the connection string but it looks like assigning it to the environment causes it to break (the ListFeatureClasses runs forever until I interrupt it)&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 14:59:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/access-sde-from-data-store-in-python-toolbox/m-p/1491775#M70813</guid>
      <dc:creator>sbrowneotogo</dc:creator>
      <dc:date>2024-06-13T14:59:16Z</dc:date>
    </item>
  </channel>
</rss>

