Create a way to update sde connection paramaters

410
5
a month ago
Status: Open
Labels (1)
LukeSavage
Occasional Contributor II

 

 

####Update SDE Files using TLS Security for SQL Server
import os
import operator
import arcpy

dbloc = r"D:\MapsandGeodatabases\dbconnects/"
dblist = os.listdir(dbloc)
dblocnew=r"D:\MapsandGeodatabases\newdbconnects/"
user='xxx'
passw='xxx'

for dbl in dblist:
    if '.sde' in dbl:
        try:
            desc = arcpy.Describe(dbloc + dbl)
            cp = desc.connectionProperties
            cpdb = cp.database
            inst = cp.instance[+14:]
            enco = ";Encrypt=yes;TrustServerCertificate=yes"
            arcpy.management.CreateDatabaseConnection(
                out_folder_path=dblocnew,
                out_name=dbl,
                database_platform="SQL_SERVER",
                instance=inst+enco,
                account_authentication="DATABASE_AUTH",
                username=user,
                password=passw,
                save_user_pass="SAVE_USERNAME",
                database=cpdb,
                schema="",
                version_type="BRANCH",
                version="",
                date=None,
                auth_type="",
                project_id="",
                default_dataset="",
                refresh_token='',
                key_file=None,
                role="",
                warehouse="",
                advanced_options=""
            )
            print(arcpy.GetMessages())
        except Exception as e:
            print(f"issue with sde connection file {dbl}: {str(e)}")
            continue

 

 

Tags (2)
5 Comments
MErikReedAugusta

You might want to use the Code Block functionality in these boards when you post code: https://community.esri.com/t5/python-documents/posting-code-with-syntax-highlighting-on-geonet/ta-p/...

All of your indentation was lost when you pasted it in, which makes your code illegible and nonfunctional. Including it in the TXT file helps somewhat, but not everyone's going to want to go to a separate file, assuming they even see it. Plus, neither your pasted code nor the TXT file has syntax highlighting, which slows reading for some of us.

LukeSavage

Fixed code highlighting.  If anyone has questions, please let me know. 

HannesZiegler
Status changed to: Needs Clarification

@LukeSavage Thank you for submitting your idea, do you mind providing some more context/background?

 

LukeSavage

@HannesZiegler There is no way to programmatically or through a batch process update existing sde connection files for the additional properties.  In fact, there is no geoprocessing tool to do this.  Each connection needs to be manually updated.  For medium to large organizations that have many sde connections, this is a problem.  The industry is now leaning towards encrypting database instances via tls connections.  Once this is done for the GIS person who manages the enterprise geodatabase stack, it is very costly and time consuming.  Below is a screenshot of what is added in order to work.  Does this help answer your question?

LukeSavage_0-1713289796152.png

 

HannesZiegler
Status changed to: Open

@LukeSavage Yes that is very helpful, thank you for the additional details!