Centralizing database connection strings and publishing GP Services

261
6
06-05-2020 07:48 PM
MollyFoley
Regular Contributor

I have created a python script that contains all of my database connection strings and when I'm working locally, I can just import those strings like you would any regular module and use them. When I publish a geoprocessing service though, I can't figure out how to use an imported module like this because those connection strings won't be made into g_ESRI variables. My goal is to have one central place to update all my connection string paths if they change in the future, rather than going into 50 different scripts and changing each one. 

This is what my database connection python file (DatabaseConnections.py) looks like:

hb_db_con = r'C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\FocalAreas_HabitatWriter.sde'
fa_db_con = r'C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\HbMon_HabitatWriter.sde'

#So on and so forth

The top of the geoprocessing service I publish imports those connections like so:

from DatabaseConnections import hb_db_con, fa_db_con

fc1 = hb_db_con + "\blah.DBO.blahblah"
fc2 = fa_db_con + "\blah2.DBO.blahblahblah"‍‍‍‍

I have copied DatabaseConnections.py to the server's python library so it can find the connection strings, but obviously it doesn't convert them to where the server should find the data and instead just takes the hard-copied connection string and goes searching, coming up with nothing. Is there a way to centralize database connection strings in your code and still make it publishable? 

Tags (1)
0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

What's the authentication on your DBs?

0 Kudos
MollyFoley
Regular Contributor

Database authentication is used for geoprocessing services.

0 Kudos
ZacharyHart
Regular Contributor

Have these various DB connections been registered with your Server's Data Store?

0 Kudos
MollyFoley
Regular Contributor

If you're talking about Data Store proper (the thing that comes with ArcGIS Enterprise), we don't have that or portal installed. Just Server. But all the databases are registered with the server.

0 Kudos
ZacharyHart
Regular Contributor

Ok, I see. What if you put your SDE connection files in a shared network location and have your script point to those? The location would have to be made available to the ArcGIS service account. Not sure if you used a domain or local machine account for your server setup.

0 Kudos
MollyFoley
Regular Contributor

That's a good idea, I can give that a shot. Thanks.

0 Kudos