Updating connection info via python from SDE to File geodb - with a feature dataset

4951
13
Jump to solution
01-30-2019 08:05 PM
FraserHand1
Esri Contributor

Hi,

I'm clipping data and moving to a file geodb from SDE and fixing up datasources  for a symbolised Pro project before publishing.

This works for the main part unless the feature class is in a feature dataset. Doing the below works for 90% of my feature classes - if the FC is in a FD the source breaks as Pro can't find the FD in the filegeodb. (note the validate false was for troubleshooting)

con_props = {'connection_info':{'database': temp_filegeodb,
                                'authentication_mode': '',
                                'dbclient': '',
                                'db_connection_properties': '',
                                'password': '',
                                'instance': '',
                                'server': '',
                                'user': '',
                                'version': ''},
             'dataset': name,
             'workspace_factory': 'File Geodatabase',
             'feature_dataset': ''
             }
print(con_props)
a_layer.updateConnectionProperties(a_layer.connectionProperties, con_props,validate=False)

yet I can't see a flag to clear the feature dataset from the layer.

So we end up with a broken datasource as the layer is still looking for the original feature dataset. Is there an easy way to clear this - I haven't seen anything in the doco.

Before:

After:

surely this property is exposed in the connection_info dictionary? Right?

Ta

Fraser

13 Replies
LindsayMillard1
Emerging Contributor

Hi Jeff,

My organisation has just upgraded to ArcGIS Pro 2.5.2, so won't be going to 2.6 for at least a little while.

Is there a way in 2.5.2 to adapt your 'workaround' script above to repoint a project's data sources from a file geodatabase to an enterprise (SQL) geodatabase?

Our databases are typically flat in structure, without feature datasets, joins or other complications, so we pretty much want to replace the .gdb path with a .sde path, although I know it's not that simple...

Given the different connection properties for file and enterprise geodatabases, I'm not sure how to translate this to your above solution.

Any assistance would be most appreciated!

Lindsay.

0 Kudos
JeffMoulds
Esri Contributor

Re-sourcing data from File GDB to Enterprise GDB should be pretty straight forward in 2.5.2, especially if data set names are the same between the two geodatabases. For example:

import arcpy 
aprx = arcpy.mp.ArcGISProject(r'C:\Projects\YosemiteNP\Yosemite.aprx')
aprx.updateConnectionProperties(r'C:\Projects\YosemiteNP\Local_Data\YosemiteLocal.gdb',
                                r'C:\Projects\YosemiteNP\DBConnections\Server.sde')
0 Kudos
LindsayMillard1
Emerging Contributor

Hi Jeff,

Thanks very much for your fast response.

I agree that re-sourcing should be straightforward... but it doesn't work for me as you have it scripted above.

I can run the equivalent of your script within an ArcGIS Pro session and, despite running for a period of time, the data sources remain unchanged.

Likewise, I can run the script in a standalone Python shell that saves a copy of the 'updated' APRX with the same non-results.

I assume this is related to BUG-000112574, so was hoping to use the 'Alternate Solution' proposed on that page of two dictionaries, but there is no clear direction on how to do this.

Are you able to confirm that your script runs in ArcGIS Pro 2.5.2?

If not, can you advise on the appropriate dictionary syntax to use to achieve the required outcome?

Thanks again, your assistance is much appreciated.

0 Kudos
JeffMoulds
Esri Contributor

From the description of your workflow, the process should be pretty straight forward. The bug you mentioned shouldn't be a factor. And the little three line script in my previous reply should work. Can you email me a small project package that demonstrates the problem? jmoulds@esri.com

0 Kudos