<?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: Python script not looping through SDE databases in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189411#M14541</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest skipping the dirpath approach, and keep it in arcpy by either first setting the workspace env or going directly to your sde connections. Here is an example of using the workspace env:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C\users\XXX\AppData\Roaming\Esri\Desktop10.7\ArcCatalog\SDE'&lt;/SPAN&gt;
gdbList &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListWorkspaces&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'*'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SDE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; gdb &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; gdbList&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="string token"&gt;"""execute your analyze compress
       routines; I suggest wrapping
       them in a try/except block"""&lt;/SPAN&gt;




‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume that user XXX has admin rights to the Egdbs....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edited to ad:&amp;nbsp; Looks like Joshua caught the actual error....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:32:39 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-12-11T09:32:39Z</dc:date>
    <item>
      <title>Python script not looping through SDE databases</title>
      <link>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189408#M14538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to loop through a list in python and the script is only processing the first database and not the remainder of the list. Where is the script wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;1 # import packages
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;2 import &lt;/SPAN&gt;os&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;arcpy&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;time&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;smtplib
&lt;SPAN style="color: #808080;"&gt;3 # setup workspace and SDE databases in folder
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;4 for &lt;/SPAN&gt;dirpath&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;dirnames&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;filenames &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;os.walk(&lt;SPAN style="color: #a5c261;"&gt;r'C:\Users\XXX\AppData\Roaming\Esri\Desktop10.7\ArcCatalog\SDE'&lt;/SPAN&gt;):
5    &lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;file &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;dirpath:
6        &lt;SPAN style="color: #cc7832;"&gt;print &lt;/SPAN&gt;filenames
7        string = &lt;SPAN style="color: #a5c261;"&gt;'C:/Users/XXX/AppData/Roaming/Esri/Desktop10.7/ArcCatalog/SDE/'
&lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;8        &lt;/SPAN&gt;new_list = [string + x &lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;x &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;filenames]
9        &lt;SPAN style="color: #cc7832;"&gt;print &lt;/SPAN&gt;new_list
10       &lt;SPAN style="color: #cc7832;"&gt;for &lt;/SPAN&gt;database &lt;SPAN style="color: #cc7832;"&gt;in &lt;/SPAN&gt;new_list:
11          &lt;SPAN style="color: #808080;"&gt;# Block new connections to the database.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;12          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;'The database is no longer accepting connections{}'&lt;/SPAN&gt;.format(database))
13          arcpy.AcceptConnections(database&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;False&lt;/SPAN&gt;)
14          &lt;SPAN style="color: #808080;"&gt;# Wait 5 minutes
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;15          &lt;/SPAN&gt;time.sleep(&lt;SPAN style="color: #6897bb;"&gt;5&lt;/SPAN&gt;)
16          &lt;SPAN style="color: #808080;"&gt;# Disconnect all users from the database.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;17          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Disconnecting all users"&lt;/SPAN&gt;)
18          arcpy.DisconnectUser(database&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;"ALL"&lt;/SPAN&gt;)
19          &lt;SPAN style="color: #808080;"&gt;# Run the compress tool.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;20          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Running compress"&lt;/SPAN&gt;)
21          arcpy.Compress_management(database)
22          &lt;SPAN style="color: #808080;"&gt;# Allow the database to begin accepting connections again
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;23          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Allow users to connect to the database again"&lt;/SPAN&gt;)
24          arcpy.AcceptConnections(database&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #8888c6;"&gt;True&lt;/SPAN&gt;)
25          &lt;SPAN style="color: #808080;"&gt;# Rebuild indexes in database(s)
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;26          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Rebuilding indexes on the system tables"&lt;/SPAN&gt;)
27          arcpy.RebuildIndexes_management(database&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;"SYSTEM"&lt;/SPAN&gt;)
28          &lt;SPAN style="color: #808080;"&gt;# Updating statistics in database(s)
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;29          &lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Updating statistics on the system tables"&lt;/SPAN&gt;)
30          arcpy.AnalyzeDatasets_management(database&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a5c261;"&gt;"SYSTEM"&lt;/SPAN&gt;)
31          &lt;SPAN style="color: #cc7832;"&gt;print &lt;/SPAN&gt;(&lt;SPAN style="color: #a5c261;"&gt;"Finished"&lt;/SPAN&gt;)
32          &lt;SPAN style="color: #cc7832;"&gt;break
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;33      break
&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;34  break&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189408#M14538</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2021-12-11T09:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python script not looping through SDE databases</title>
      <link>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189409#M14539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Line #32, your break statement is terminating the loop after the first pass.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2019 14:28:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189409#M14539</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-09-16T14:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Python script not looping through SDE databases</title>
      <link>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189410#M14540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joshua&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Sep 2019 14:29:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189410#M14540</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2019-09-16T14:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python script not looping through SDE databases</title>
      <link>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189411#M14541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest skipping the dirpath approach, and keep it in arcpy by either first setting the workspace env or going directly to your sde connections. Here is an example of using the workspace env:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C\users\XXX\AppData\Roaming\Esri\Desktop10.7\ArcCatalog\SDE'&lt;/SPAN&gt;
gdbList &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListWorkspaces&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'*'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SDE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; gdb &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; gdbList&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="string token"&gt;"""execute your analyze compress
       routines; I suggest wrapping
       them in a try/except block"""&lt;/SPAN&gt;




‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume that user XXX has admin rights to the Egdbs....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edited to ad:&amp;nbsp; Looks like Joshua caught the actual error....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:32:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-not-looping-through-sde-databases/m-p/189411#M14541</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T09:32:39Z</dc:date>
    </item>
  </channel>
</rss>

