I use this script right now:

import os, arcpy

directory = r"C:\Project"
 for root, dirs, files in os.walk(directory):
  for myFile in files:
    fileExt = os.path.splitext(myFile)[1]
    if (fileExt == ".mxd"):
        fullPath = os.path.join(root, myFile)
        print myFile

        myMap = arcpy.mapping.MapDocument(fullPath)
        analysis = arcpy.mapping.AnalyzeForMSD(myMap)

for key in ('messages', 'warnings', 'errors'):
print "----" + key.upper() + "---"
vars = analysis[key]
for ((message, code), layerlist) in vars.iteritems():
print "    ", message, " (CODE %i)" % code
print "       applies to:",
for layer in layerlist:
print layer.name,

It runs on many project mxds. And every time it analyzes a mxd file I`m asked the connection dialogue and have to enter the connection details.

Is there a way to open a database connection that is valid for all mxd?

  • 5
    Just a guess - try the Create ArcSDE Connection file tool: resources.arcgis.com/en/help/main/10.1/index.html#//… I do know when you run the tool it validates by making a connection to SDE. So, I'm thinking by using this it might persist the open connection in your script, thus allowing you to analyze. – KHibma Feb 25 '13 at 21:22
  • Didn`t work for me – Trashken Feb 28 '13 at 9:57

I'm going to stand by my answer I posted as a comment. In the following script:

import arcpy

myMap = arcpy.mapping.MapDocument(r'c:\temp\sde.mxd')
analysis = arcpy.mapping.AnalyzeForMSD(myMap)
print analysis

I get this:

{'errors': {(u"Layer's data source is inaccessible", 3): [, ]}, 'messages': {}, 'warnings': {}}

(with the dialog box as you explain)

However, in this script which uses CreateDataBaseConnection (or use CreateArcSDE if you're using the SDE tier to connect through):

import arcpy


myMap = arcpy.mapping.MapDocument(r'c:\temp\sde.mxd')
analysis = arcpy.mapping.AnalyzeForMSD(myMap)
print analysis

I get:

{'errors': {}, 'messages': {(u'Layer draws at all scale ranges', 30003): []}, 'warnings': {}}

If you have layers coming from multiple databases with multiple credentials you'll have to create a connection for each one of those. If this is a script you'll be running multiple times you'll either need to turn on overwriteOutput or delete the .SDE files prior to running again.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.