Python: Add Database and Server Connections to ArcGIS Pro Favorites

One of the sticking points of ArcGIS Pro is its project-based nature and difficulty accessing data sources that aren’t already included in the project.  This has been somewhat made easier with the “Favorites” section of the Catalog View that was added in later releases after many complaints.  However yet still, adding Databases and Server connections to populate the Favorites list is a manual process in ArcGIS Pro and can take quite a bit of time depending on how many there are to add.

To get around the manual process I created a Python script that generates the Favorites.json file that ArcGIS Pro uses to read and populate the Favorites list from. This file references the connection file paths so make sure you don’t move them later on. Now with this we’re able to add in a couple hundred connections in a matter of seconds as opposed to doing each one-by-one.

Here’s the step-by-step in order to do this and save lots of time.

  1. Navigate to your ArcCatalog folder where connection files are traditionally stored by ArcMap: C:\Users\<User Name>\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog (if you’re using a different version of ArcMap check in that folder)
  2. Select all the .SDE and .AGS files and copy them to: C:\Users\<User Name>\AppData\Roaming\ESRI\ArcGISPro\Favorites
  3. Just to be safe, backup the Favorites.json file in the ArcGIS Pro\Favorites folder.  (this could be empty or not exist if you have not added any Favorites yet)
  4. Run the following script, it will prompt for the folder to look in for the connections so have that ready to paste in.
    import os, glob
     
    folder = raw_input('Folder: ')
     
    json = open(folder + "\\Favorites.json","w+")
     
    json.write('{"Items":[')
     
    items = []
     
    for f in glob.glob(folder + '\*'):
        if f.endswith('.sde'):
            print ('Adding SDE Connection ' + os.path.basename(f) + ' to favorites')
            items.append('{"TypeId":"database_egdb","Path":"' + f.replace('\\','\\\\') + '","Id":"","url":"","name":"'+ os.path.basename(f) + '","persistFavorite":false}')
        if f.endswith('.ags'):
            print ('Adding Sever Connection ' + os.path.basename(f) + ' to favorites')
            items.append('{"TypeId":"serverConnection_ags","Path":"' + f.replace('\\','\\\\') + '","Id":"","url":"","name":"'+ os.path.basename(f) + '","persistFavorite":false}')
     
    json.write(','.join(items))
    json.write(']}')
    json.close()
  5. Now when you open ArcGIS Pro you should see the full listing of the database and server connections to choose from and add to your project. You can also right-click and select “Add To New Projects” in order for the connection to be added to the Databases or Servers folder of each new project that you open. This would be good to do on all of the GIS Repository connections and any others that are commonly used by your department.

This was put together fairly quickly so if you have any issues or ideas for improvements, please let me know.

3 Comments

  1. John Hickok

    Finally implemented – This is a most useful post! Thanks again!

  2. John Diaz

    Thanks Tom! You could not have made this any easier for us. Worked perfectly.

  3. Daniel Hoffman

    Very cool Tom, thank you! Just tried it and it worked great. Yes, that was (and is) an annoying thing about Pro…this is a nice workaround

Comments are closed.