####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
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.
Fixed code highlighting. If anyone has questions, please let me know.
@LukeSavage Thank you for submitting your idea, do you mind providing some more context/background?
@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?
An additional/related enhancement would be to have a way to open a connection file without having it attempt to connect to the database. When the connection is "broken" having to wait for the timeout before being able to access the properties is crazy slow. Something like a "open but don't hydrate" method when all we want to do is access the properties of the connection file rather than actually connecting to the database.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.