I wonder if it is possible for a published Python tool in ArcGIS Server 10.6.1 (not Portal/Enterprise, just a stand-alone Server) to make use of a registered database connection. So, what I mean is, I have an instance of ArcGIS Server 10.6.1, and it has several registered database connections to an SDE on another machine.
I would like to publish a Python geoprocessing tool to that ArcGIS Server that can use these "pooled" SDE connections to read or write data, so I do not have to upload a separate SDE connection file for every GP tool every time I re-publish it or change the password. This would be similar to how Java web apps use a single Tomcat database connection, which is more efficient and easier to maintain.
But I can't figure out of this is possible or what the syntax would be. Here is a simple example of what I'd like to do in Python. All this script does is open up and list the datasets in an SDE schema:
<SPAN class="keyword token">import</SPAN> sys
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
scriptPath <SPAN class="operator token">=</SPAN> sys<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>scriptPath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"read_only_connection.sde"</SPAN><SPAN class="punctuation token">)</SPAN>
ds <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>ds<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
dataset_file <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>scriptPath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"datasets.txt"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"w"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> d <SPAN class="keyword token">in</SPAN> ds<SPAN class="punctuation token">:</SPAN>
dataset_file<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>d <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
dataset_file<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If I copy up read_only_connection.sde to the script's directory after I publish, it will work. But read_only_connection.sde is already imported as a registered database on the server called read_only_connection (no .sde extension). How do I reference it from within Python? Is it even possible?