English

How To: Automate the creation of sdeconnection files for multiple users

Summary

GIS managers and database administrators sometimes desire to create sdeconnections for multiple users in their environment.

Procedure

The Python script below provides a way of automating the process of creating sdeconnection files based on different users and passwords.

  1. Modify the parameters in the script below based on the environment such as serverName, serviceName, databaseName, etc.

    For example:

    folderName = r"C:\sdeconnections"
    serverName = "Prod1"
    serviceName = "sde:sqlserver:Prod1\sql2008r2"
    databaseName = "Replica"
    authType = "DATABASE_AUTH"
    saveUserInfo = "SAVE_USERNAME"
    versionName = "SDE.DEFAULT"
    saveVersionInfo = "SAVE_VERSION"

  2. Populate the username parameter based on all user names and passwords that are needed:

    For example, 'sde' is user and 'sde' is password is written as 'sde':'sde'.

    username = {'sde':'sde', 'gisadmin':'gisadmin','User2':'user2'}

  3. Code:
    # Import system modules
    import arcpy, os, string
    from arcpy import env

    # Set environment parameters
    arcpy.env.overwriteOutput = True

    # Set variables
    folderName = r"C:\sdeconnections"
    serverName = "Prod1"
    serviceName = "sde:sqlserver:Prod1\sql2008r2"
    databaseName = "Replica"
    authType = "DATABASE_AUTH"
    saveUserInfo = "SAVE_USERNAME"
    versionName = "SDE.DEFAULT"
    saveVersionInfo = "SAVE_VERSION"

    username = {'sde':'sde', 'gisadmin':'gisadmin','User2':'user2'}

    for key, val in username.iteritems():
    arcpy.CreateArcSDEConnectionFile_management (folderName, key + "@" + serverName + ".sde", serverName, serviceName, databaseName, authType, key, val, saveUserInfo, versionName, saveVersionInfo)

    print "Created connection file : " + key + "@" + serverName + ".sde"