Select to view content in your preferred language

Reparing datasources in Sql server enterprise geodatabase

703
3
12-20-2022 01:14 PM
Labels (1)
StephenCochrane
New Contributor III

I am writing a script used for repairing data sources in an ArcGIS Pro project. All the data is located in SQL server enterprise databases. For various reasons I would like to determine the sde connection file used when the layer was added to project.

Looking at the documentation for the arcpy.mapping module I get a bit confused. Under the dataSource property for the layer class it is stated:

”TIP: Enterprise geodatabase layers in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.”

This would indicate that I will not be able to retrieve the SDE file used when the data was added.

However, when I look at the documentation for the updateConnectionProperties method (again on the layer class) you need to provide the path of the original connection sde file as well as the new one. Furthermore, my initial tests shows that if you provide a dummy original file the update is not carried out. So, I guess that the path to original sde connection file must be stored in the layer info somehow. Is there any way to retrieve this?

In the setup I have, multiple sde files are in used, and if the script could identify these automatically it would save a lot of bookkeeping.

0 Kudos
3 Replies
RhettZufelt
MVP Notable Contributor

Not sure by code, but the original source is in there.  In Pro, Catalog, right click the database and get properties and you will see the full path to the connection file.

Don't know if this helps though unless you just need to enter it initially........

0 Kudos
MikeVolz
New Contributor III

Are you looking to use this script for many aprx files or is this more of fixing individual aprx files with many SDE connections?

0 Kudos
StephenCochrane
New Contributor III

Well, it is going to be part of a system where many different organisations have one or more databases for setting up projects. We have one template aprx for showing/altering the data in a specific database (so one aprx per database). As an administrative operation, we need to make a copy of the template aprx and replace the data sources each time a new database is made available in the system.

But sometimes we also have push changes made in one of the specific aprx files back to the template (or even worse to a subset of all the other aprx files). For these cases some bookkeeping will be required and identifying the current sde connection could help in this regard.

0 Kudos