Hello,
I am having difficulty connecting to my enterprise geodatabase and reading data.
My code below is unable to read the feature class.
myWorkspace = 'C:/xxx/Connection.sde'
# myWorkspace = 'Database Connections/Connection'
arcpy.env.workspace = myWorkspace
featureClassPath = "myGIS.DBO.myData"
print (str(arcpy.Exists(featureClassPath)));
When I log into ArcMap I usually have to click on my SDE connection before it just opens.
What am I missing?
Did the code # myWorkspace = 'Database Connections/Connection' also not work for you? I believe you did not need to use the full explicit path to the SDE connection file back in v10.0, so I'm not sure why that would not have worked for you. It could be the / in the path. Try \ instead and even try using the "r" convention that is talked about in other python posts.
Does a function like ListFeatureClasses work to list any feature classes? If not, is there an error? If an error, what error? If ListFeatureClasses works and lists feature classes, then see if the feature class you are checking existence on is in the list.
Exactly,
are you sure that this featureClassPath = "myGIS.DBO.myData" is correct.
Try the ListFeatures inside the workspace first to make sure you have the path correctly defined.
I backed up to connecting to the workspace.
The following yields false.
myWorkspace = r'Database Connections\Connection to server.sde'
arcpy.env.workspace = myWorkspace
print (str(arcpy.Exists(arcpy.env.workspace)));
Is SDE at the same version as ArcGIS Desktop v10.0?
Is Connection to server.sde' the actual name of the SDE connection or are you just putting in placeholder text?
How are you coming up with r'Database Connections\Connection to server.sde' ? Is this string being returned to you from some code? Are you seeing it in a dialog box somewhere? Are you looking at the name in ArcCatalog under the Database Connections folder?
I ask these questions because the only way for your workspace check code to return False is if the SDE file doesn't exist or you don't have permissions to access it.
I still cannot connect even with the following code, which was exported from a working ModelBuilder workflow.
myDataset = r"Database Connections\\Connection to server.sde\\database.abc.dataset"
fieldList = arcpy.ListFields(myDataset)
Again, I don't seem to have a persistent connection to the SDE. When I log into ArcMap, I need to click the connection and then it loads. I think this may be the problem. How can I make my connection persistent?
Try using ArcToolbox to run a simple tool (like Get Count). Was it successful? If so, open the Results Window, right click the tool result and copy the python snippet.
Paste the snippet code into your Python interpreter and run it. Does it error?
I want this to run independently of ArcMap. Hence, the snippet will only work in ArcMap.
I am only try to find how to connect to the SDE connection with code from the Python command prompt. I have to open ArcMap to connect to the SDE each time.