<?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: Cannot Acces SDE Connection File Properly using Arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710823#M55106</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you show how you completed this as we have the same issue in our organization.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Aug 2019 18:47:13 GMT</pubDate>
    <dc:creator>AndrewSmith26</dc:creator>
    <dc:date>2019-08-07T18:47:13Z</dc:date>
    <item>
      <title>Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710817#M55100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am testing a way around accessing sde connections using arcpy. I have 2 existing sde databases connected in ArcCatalogue that require passwords anytime I go to connect to them. It seems that there is no way to access existing database connections using arcpy (that I can find anyways). You are forced to create new ones every time if you want to do this in a script using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CreateArcSDEConnectionFile_management (folderName, fileName, serverName, serviceName, databaseName, authType, username, password)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems completely redundant to do so if I already have the connection set up. There should be a function to access these existing connection so that a programmer can just build a tool that allows the user to enter their user name and password without re-creating the connection. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh but what. You sort of can if you set your environment workspace in your script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env

env.workspace = r"Database Connections\blah.sde"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you do this and run the script from the ArcGIS GUI, the regular database connection prompt will pop up which should allow you to login. The problem I have having is, the prompt will come up but anytime I click on the window, the ArcGIS GUI will override it an won't allow me to type anything into the username and password fields.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I tried to get creative and decided to create a new connection file and then immediately after, I tried to delete it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

# Set variables
folderName = r"Database Connections"
fileName = "Connection to SDE.sde"
serverName = "someserver"
serviceName = "5151"
databaseName = ""
authType = ""
username = "username"
password = "password"

arcpy.CreateArcSDEConnectionFile_management (folderName, fileName, serverName, serviceName, databaseName, authType, username, password)

arcpy.Delete_management(r"Database Connections\Connection to SDE.sde")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The thinking was that I would just build the tool to allow the user to enter their username and password, pass that into the arcpy.CreateArcSDEConnectionFile function, do some processing and then delete the connection file at the end using &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;arcpy.Delete_management&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is, it schema locks every time the script does the delete. This is weird because I simply created and deleted in one foul swoop. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm at a loss. I need to figure out a way to access a database connection. I need to either:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Solve the issue with the ArcGIS GUI overriding the database connections login prompt&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Find a way to release the schema lock so that I can delete any database connections I create during the script&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Or find some other weird and wonderful to accomplish this&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Mar 2014 22:10:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710817#M55100</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2014-03-08T22:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710818#M55101</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;SPAN&gt;Assume the path to your connection file is stored in variable 'con'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried setting env.workspace to something else and calling &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000000m000000"&gt;arcpy.ClearWorkspaceCache_management(con)&lt;/A&gt;&lt;SPAN&gt; before you try arcpy.Delete_management(con)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is not the same as disconnecting via ArcCatalog but it's worth a try.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it doesn't help, is os.remove(con) an option?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Filip&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Mar 2014 22:40:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710818#M55101</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2014-03-09T22:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710819#M55102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Filip,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried clearing the workspace cache but I still annot delete the database connection. I find it very odd that on one line of code I can create a database connection, but on the very next line I cannot delete it (even after clearing the cache).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 15:47:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710819#M55102</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2014-03-12T15:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710820#M55103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As Filip suggested, use os.remove(). That is the standard method of deleting files in Python on Windows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;If the specified item is a workspace, all contained items are also deleted. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even though it also says.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Deleting a database connection file does not delete the ArcSDE database. A database connection file is simply a shortcut to the database. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bottom line is I would never use arcpy.Delete_management() to delete anything but a feature class.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 16:48:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710820#M55103</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-12T16:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710821#M55104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks matt. I guess I was just going by the helpfile:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000052000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000052000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It specifically states that you can delete a Database Connection file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I decided to hack into the validator class (and by hack I mean, press the edit button &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ) and just added set the workspaces to fire up upon the tool initiation. Now instead of creating a new connection file, I just open the tool and the Database Connections prompt comes up twice for me to log into the 2 sde DB's I need to access.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will try the os.remove method, though, because ideally I'd like to build the GUI to have built in parameters with a string for the username and an encrypted string for the password taht I can pass into a connection file so the user can do all of his/her setup in one window.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 16:57:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710821#M55104</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2014-03-12T16:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710822#M55105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should be able to do that easily as a parameter. Are you creating a custom GUI or using Esri addins/tools?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, have you tried CreateDatabaseConnection_management()? I use them for the direct connects. I did have some other issues actually with creating connection files and referencing a default version. Had to use arcobjects to get around it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 17:03:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710822#M55105</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-03-12T17:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Acces SDE Connection File Properly using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710823#M55106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you show how you completed this as we have the same issue in our organization.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2019 18:47:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-acces-sde-connection-file-properly-using/m-p/710823#M55106</guid>
      <dc:creator>AndrewSmith26</dc:creator>
      <dc:date>2019-08-07T18:47:13Z</dc:date>
    </item>
  </channel>
</rss>

