I am facing a very weird issue in setting the workspace. When I setup the workspace inside python window in ArcMap/ArcCatalog, it just works fine. But the moment I do the same in a standalone python script, the things do not work at all. I tried other options like creating connection file in scratch folder and then setting it as a workspace but still no luck. I am facing this issue on ArcGIS Desktop 10.2.1 and my database is 64 bit Oracle.
I had ArcGIS Pro 2.1 installed on the same machine hence I also tried the same thing after uninstalling ArcGIS Pro but still no luck.
Can you browse the database in ArcCatalog once you have opened the connection file?
Just setting env.workspace = "my connection file.sde" has always worked for me.
What happens?
Hi Neil,
Yes, I can browse the database in ArcCatalog/ArcMap and walk around the featureclasses/datasets etc. But this is driving me crazy as env.workspace = "my connection file.sde" is no way working for me.
What happens when you set env.workspace = "my connection file.sde" in your python script?
Are you using os.path.join() to construct the path pointer to the connection file? Or just raw strings.
I set up my workspace in the following manner
arcpy.env.workspace = r"Database Connections\Connection to sde.sde"
# Just for sake of testing, I am trying to print all the datasets
print arcpy.ListDatasets()
The above code snippet prints all the datasets list if I run it in python window withing ArcMap but If I try to run the same snippet in a script, it Print "None"
in a standalone script it will need more information that provided since the script has no information as to where the project is. Can you use a full path to your database connection
Create Database Connection—Data Management toolbox | ArcGIS Desktop
Hi Dan,
Thanks for the suggestion. I have tried that option as well and it didn't work.
This is not going to work:
arcpy.env.workspace = r"Database Connections\Connection to sde.sde"
The script has no idea where your user profile will be.
Copy the full path as Joe suggests.
Or copy the sde file to a local space and use that.
I have tried with full path as well, no luck!
Let's see exactly what your are using.