This does not seem to work...
I am using CreateDatabaseConnection_management instead of CreateArcSDEConnectionFile_management because I want to make a direct connection to SQL Server instead of an application connection.
But it is NOT suppressing the dialog box.
The script pauses and will not continue until I click cancel or close the dialog box.
Here is my code....
sde = arcpy.CreateDatabaseConnection_management("foldername", "filename", "SQL_SERVER", "servername", "DATABASE_AUTH", "username", "password", "SAVE_USERNAME", "database", "#", "TRANSACTIONAL", "sde.DEFAULT")
mxd = arcpy.mapping.MapDocument("path to mxd")
Seems like arcpy.mapping.MapDocument should be rewritten to accept login credential parameters.
You may be getting such issues because you are not logged in to a secured mapservice, not the SDE.
A mapservice connection is not connected to an SDE connection and would require it's own credentials. When adding such a service in ArcMap, it will use the username and password of the GIS Server connection, so you don't have to put it in, but it is there. Check your mapservice layers in Properties>Source and if you see a username under "User" then it is using a username/password to access that service.
As for how to do that in python, I'm not sure. I'm assuming it would be in the 'N/A' portion of your code below, much like in the SDE connections.
if lyr.serviceProperties["ServiceType"] == "MapServer":
SOURCE_PATH = lyr.serviceProperties.get('URL', 'N/A')
Hope this helps!
The dialog box is prompting for SDE connection credentials.
So far the old map documents I have been testing are so old (2005) that ArcGIS Server did not even exist yet.
I manually opened one of the trouble documents and the issue is a secured layer that does not have the login credentials saved.