Establish SDE connection with layer files that have no stored username or password

Discussion created by union77 on Feb 3, 2011
I'm writing a script that iterates through layer files on network and verifys that they all work and there are no broken data sources. No SDE connection information is stored within the layer file.

Each time I run my script I recieve a prompt to enter the SDE username and password.

Whats the proper method/syntax in order to pass credentials from a connection file into a layer file?


import arcpy, os

path = "x:/"

for fileName in os.listdir(path):
    fullPath = os.path.join(path, fileName)
    if os.path.isfile(fullPath):
        basename, extension = os.path.splitext(fullPath)
        if extension == ".lyr":
            lyr = arcpy.mapping.Layer(fullPath)
            print "Broken Layer File: " + fullPath
            brknList = arcpy.mapping.ListBrokenDataSources(lyr)
            for brknItem in brknList:
                print "\t" + brknItem.name