arcpy: Could not open SDE workspace - sde filename dependency?

2257
5
09-21-2018 01:28 AM
LionelMartz
New Contributor II

Hello,

I am having trouble with a arcpy script. I'm actuall not that familiar with python in general, and the current issue is really making me sick.

On a new environment, I installed a new Database and I want to setup there the same maintenance task as we already have on another environment. Part of this maintenance is a python script for compress, etc. But on the new environment the scripts aren't working. It always runs into error "TypeError: Could not open SDE workspace"

So I made some tests on the current environment and found some very strange behaviour.

I have the following script (reduced to only few lines)

test.py

conn = 'C:\SDE\da.sde'
import arcpy
arcpy.AcceptConnections(conn, True)

the file da.sde exists.

But when I rename the file to test.sde, and change it of course in the pythin script, it throws:

C:\SDE>test.py
Traceback (most recent call last):
  File "C:\SDE\test.py", line 5, in <module>
    arcpy.AcceptConnections(conn, True)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\__init__.py", line
 1677, in AcceptConnections
    return gp.acceptConnections(sde_workspace, accept_connections)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\geoprocessing\_bas
e.py", line 479, in acceptConnections
    return self._gp.AcceptConnections(sde_workspace, accept_connections)
TypeError: Could not open SDE workspace.

(This is also the actual error I always get on the other environment.)

Switching both back to da.sde, works again.

I've testes several different filenames.

"da.sde" - works!

"test.sde" - fail

"datest.sde" - works

"abcde.sde" - fail

"wtf.sde" - works

"lmgtfy.sde" - works

"prod_sde.sde" - works

"b_prod_sde.sde" - fails

I am not sure that the nameing is related to the issue on the other environment. But I got a little desperate with it, so that I hope unterstanding the nameing issue, may help me to make the script run elsewhere.

Lionel

0 Kudos
5 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Some failures

pth = "C:\SDE\test.sde"

print(pth)   # ---- ooops
C:\SDE  est.sde

pth = "C:\SDE\abcde.sde"  # ---- try again

print(pth)   # ----
C:\SDEbcde.sde‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

start by raw encoding your file paths

conn = r'C:\SDE\da.sde'  # ---- not the r in front of the path‍‍‍‍

Now raw encode them

pth = r"C:\SDE\test.sde"

print(pth)
C:\SDE\test.sde

pth = r"C:\SDE\abcde.sde"

print(pth)
C:\SDE\abcde.sde‍‍‍‍‍‍‍‍‍

You can use double backslashes or forward slashes if you don't want to use the little 'r'

DanPatterson_Retired
MVP Esteemed Contributor
0 Kudos
LionelMartz
New Contributor II

I've tried it, and now it works fine on current environment, independent on filename, thanks!

However, on the other environment it has no effect. still always getting the error. Printing the paths show all in the right way. Workspace works fine in ArcCatalog.

This works with python executed in ArcCatalog, gut not here.

0 Kudos
LionelMartz
New Contributor II

So obviously my initial issue on the other environment is not related to file names.

I checked out all the links I found on google.

- Everything is in 64bit, tried also both pythons

- arcpy.Exists(r"C:\SDE\test.sde") returns true

- setting arcpy.env.workspace to anything has no effect (setting it to C:\SDE and the connection fiel just test.sde)

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I got myself turned around reading through this thread.  After changing how you handle path names:

  1. In the new environment, outside of ArcCatalog, does the code work using any name for the SDE conn file?
  2. In the new environment, from within ArcCatalog, does the code work using any name for the SDE conn file?
    1. When running the code in ArcCatalog, have you connected to any enterprise geodatabases before trying to run the code?
0 Kudos