<?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 Re: Setting SDE connection as workspace in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378281#M29830</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a created a connection file and I am pretty sure it is correct, do have to call this file into the script or make sure I store it somewhere specific?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Oct 2012 18:47:02 GMT</pubDate>
    <dc:creator>MikeBly</dc:creator>
    <dc:date>2012-10-24T18:47:02Z</dc:date>
    <item>
      <title>Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378279#M29828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to run a simple script that simply copies feature datasets from one file geodatabase to another. This is successful, however now I am attempting to copy from a versioned SDE geodatabase to a file geodatabase. I have set the workspace to the SDE using the following: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set environment settings&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r"C:\Users\mbly\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\COL_LCT_Base.sde"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the script I get return code '0', assuming no errors, however nothing happens, the script does not run because i get the code within a fraction of a second. I am confused as to how to get the script to look at the SDE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do I have to create a script to connect as a direct connection with all the login credentials inside the script. I am sure this has been done many times over, this is nothing new.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas, direction?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 16:50:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378279#M29828</guid>
      <dc:creator>MikeBly</dc:creator>
      <dc:date>2012-10-24T16:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378280#M29829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think if you have the appropriate connection file (or can make one), you can save the version to the connection, correct?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then I think you can just use this to set the workspace if I'm not missing something:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r"Database Connections\COL_LCT_Base.sde"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 17:01:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378280#M29829</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-10-24T17:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378281#M29830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a created a connection file and I am pretty sure it is correct, do have to call this file into the script or make sure I store it somewhere specific?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 18:47:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378281#M29830</guid>
      <dc:creator>MikeBly</dc:creator>
      <dc:date>2012-10-24T18:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378282#M29831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure what you mean?&amp;nbsp; Are you saying you are not able to connect or do you want to know how to test the connection?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you just want to see if you're able to read something, say a fc named ownedByMe.MyFeatureClass at your connection, COL_LCT_Base.sde, you can check for existence:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
arcpy.env.workspace = "Database Connections/COL_LCT_Base.sde"

fc = "ownedByMe.MyFeatureClass"

if arcpy.Exists(fc): 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Check succeeded - all guests are here, so proceed with the party!"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'Database Connections' is simply a shortcut ArcGIS (arcpy) understands as a default location for connection files --- however, you do not have to store your connection files there and you can even create the connection 'from scratch' in the script.&amp;nbsp; If you just want to create a connection file and maybe move it to a more 'inconspicuous' location, you can do that and just refer to it with a full pathname.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, if you'd rather do something like list data available from your defined connection, there are a set of commands for that, summarized here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000011000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000011000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378282#M29831</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T17:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378283#M29832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may have to loop through the Feature Datasets and copy them one at a time, as shown in the code example below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
import os

arcpy.env.overwriteOutput = True

outFGDB = r"YOUR_FGDB.gdb"
sdeWorks = r"Database Connections\YOUR_DB_CONNECTION.sde"

arcpy.env.workspace = sdeWorks

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fd in arcpy.ListDatasets("*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing", fd, "..."
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = sdeWorks + os.sep + fd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outData = outFGDB + os.sep + fd.split('.')[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Copy_management(arcpy.env.workspace, outData, "FeatureDataset")
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sendhil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378283#M29832</guid>
      <dc:creator>SendhilKolandaivel</dc:creator>
      <dc:date>2021-12-11T17:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378284#M29833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm having a similar problem, but I cannot see what I am doing wrong. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = r"F:Replicated Data\Auto_Extract_Connection.sde"


datasetList = arcpy.ListDatasets()

print datasetList

env.workspace =&amp;nbsp; r"F:\Replicated Data\Gatekeeper_Extract.gdb"

datasetList = arcpy.ListDatasets()

print datasetList&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This returns&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[u'ElectricDataset', u'CPUDataset', u'TransmissionDataset']&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's clearly connecting to the file GDB but won't connect to the SDE one. I know the connection file is working, I can connect with it through Catalog.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378284#M29833</guid>
      <dc:creator>RonAnkeny</dc:creator>
      <dc:date>2021-12-11T17:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378285#M29834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm having a similar problem, but I cannot see what I am doing wrong. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = r"F:Replicated Data\Auto_Extract_Connection.sde"


datasetList = arcpy.ListDatasets()

print datasetList

env.workspace =&amp;nbsp; r"F:\Replicated Data\Gatekeeper_Extract.gdb"

datasetList = arcpy.ListDatasets()

print datasetList&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;This returns&lt;BR /&gt;&lt;BR /&gt;[]&lt;BR /&gt;[u'ElectricDataset', u'CPUDataset', u'TransmissionDataset']&lt;BR /&gt;&lt;BR /&gt;It's clearly connecting to the file GDB but won't connect to the SDE one. I know the connection file is working, I can connect with it through Catalog.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r'F:Replicated Data\Auto_Extract_Connection.sde'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... for ds in arcpy.ListDatasets():&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ds&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378285#M29834</guid>
      <dc:creator>benberman</dc:creator>
      <dc:date>2021-12-11T17:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378286#M29835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Typo - missing '\' in 1st pathname... I think &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;F:Replicated Data&lt;/SPAN&gt;&lt;SPAN&gt; should be &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;F:\Replicated Data&lt;/SPAN&gt;&lt;SPAN&gt;, provided you have both the given sde connection file and the gdb at that root directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You've probably seen that by now, and this is a case where using 'join' from 'os.path' would be useful in avoiding such an error, as in something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
from arcpy import env

root = r"F:\Replicated Data"

for workspace in ["Auto_Extract_Connection.sde", "Gatekeeper_Extract.gdb"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = os.path.join(root, workspace)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasetList = arcpy.ListDatasets()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print workspace, datasetList
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...or, could even use ListWorkspaces, I think (I didn't test this)-&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
from arcpy import env

root = env.workspace = r"F:\Replicated Data"

workspaces = arcpy.ListWorkspaces()

for workspace in workspaces:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasetList = arcpy.ListDatasets()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print workspace, datasetList
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378286#M29835</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T17:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Setting SDE connection as workspace</title>
      <link>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378287#M29836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Wayne. That missing \ was the ticket. I just could not see it, no matter how long I stared at the code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Apr 2014 13:09:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-sde-connection-as-workspace/m-p/378287#M29836</guid>
      <dc:creator>RonAnkeny</dc:creator>
      <dc:date>2014-04-07T13:09:17Z</dc:date>
    </item>
  </channel>
</rss>

