How do I CreateArcSDEConnectionFile in_memory?

2980
3
Jump to solution
07-05-2012 08:16 PM
AdamKerz
New Contributor
I'm using ArcGis10 with Python and trying to create a connection file in memory with CreateArcSDEConnectionFile_management.

Specifying 'in_memory' for the out_folder_path parameter gives me this error message:
ERROR 000732: ArcSDE Connection File Location: Dataset in_memory does not exist or is not supported

and leaving it blank gives:
ERROR 000735: ArcSDE Connection File Location: Value is required

The help file states that it is possible - but it's in a bit of an obscure location:
ArcGIS10 Help -> Professional Library -> Geoprocessing -> The ArcPy site package -> Mapping module -> Classes -> MapDocument, 3rd paragraph from the end of the Discussion section

"Second, the CreateArcSDEConnectionFile geoprocessing function allows you to create a connection that persists in memory."

How do I do so?

Cheers,

Adam
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
My bad, I wrote that help topic.  I don't know how else to word it.  When you create an SDE connection file, an actual file gets persisted on disk as a .sde file, but the connection information persists "in memory" allowing you to make the connection to SDE.  This technique is useful for managing map documents that contain layers that require logins.

The 4th sample on the arcpy.mapping.MapDocument object uses this:
http://resources.arcgis.com/en/help/main/10.1/#/MapDocument/00s30000000n000000/

Another sample that uses this technique is the 3rd sample on the layer class for arcpy.mapping:
http://resources.arcgis.com/en/help/main/10.1/#/Layer/00s300000008000000/


You can remove the temporary file at the end of the script.
Jeff

View solution in original post

0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor
My bad, I wrote that help topic.  I don't know how else to word it.  When you create an SDE connection file, an actual file gets persisted on disk as a .sde file, but the connection information persists "in memory" allowing you to make the connection to SDE.  This technique is useful for managing map documents that contain layers that require logins.

The 4th sample on the arcpy.mapping.MapDocument object uses this:
http://resources.arcgis.com/en/help/main/10.1/#/MapDocument/00s30000000n000000/

Another sample that uses this technique is the 3rd sample on the layer class for arcpy.mapping:
http://resources.arcgis.com/en/help/main/10.1/#/Layer/00s300000008000000/


You can remove the temporary file at the end of the script.
Jeff
0 Kudos
AdamKerz
New Contributor
OK, thanks Jeff - I understand now. If the help document is easily updateable, perhaps something like "persists in memory so that it can be automatically used by MapDocuments that need SDE logins."

Perhaps you also know of another bit of documentation that I believe to actually be incorrect (as opposed to me simply not understanding it) 🙂

The help document states that a connection file can be �??immediately deleted�?� (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002t0000000v000000 - Geoprocessing considerations for ArcSDE data). I CAN in fact delete the file using os.remove, but not using arcpy.Delete_management �?? both of which are suggested in the above referenced doc.

Basically, I'd prefer to use arcpy.Delete_management, just in case it does something more than simply delete the file, but we've fallen back to using os.remove (at the end of the script, after the connection is created and used) because it works and keeps everything clean for us.

Thanks heaps for your help,

Adam
0 Kudos
RyanCoodey
Occasional Contributor III
Hmm, so I am trying to do this same thing using arcpy in an FME job but will not be loading up a map afterwards. Generating the connection (preferably only in memory) will be followed by tools like "Compress_management" and "DeleteRows_management" (working with a network dataset and FME is a bit limited there).

Right now we have to do something like:
arcpy.CreateArcSDEConnectionFile_management("c:\Temp", "Temp.sde", ...)
arcpy.env.workspace = "c:\Temp\Temp.sde"
arcpy.DeleteRows_management("FeatureClassName")
os.remove("c:\Temp\Temp.sde")


From the examples linked above, it seems this only works with a map but not necessarily other tools, is that correct? If I remove the line to set "arcpy.env.workspace" then it doesn�??t work anymore... maybe I am missing something?

The primary reason for wanting this only in memory is because the connection that is being created is a database account with fairly high privileges, and if something were to happen where the os.remove didn�??t work that .sde file would be out there. We can protect this location behind AD I suppose, but would be nice to just not create it in the first place (auditors would like that). So that�??s my business reason for wanting a pure in memory only option, but that option doesn�??t exist today.
0 Kudos