How to delete an sde file with Python

252
2
02-25-2020 08:47 AM
JoseSanchez
Occasional Contributor III

Hello everyone,

How can I delete an sde file located in my scratch space.

prefixOutputWorkspace = r"C:\scratch\....\ConnectionToSQL.sde"

if arcpy.Exists(prefixOutputWorkspace):
          delete this sde conection

Recreate sde connection

Thanks

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

You can always use 15.1. os.remove() — Miscellaneous operating system interfaces — Python 2.7.17 documentation to remove files on the file system.

Or, if you want to stay within ArcPy modules:  Delete—Data Management toolbox | Documentation 

Deleting a database connection file does not delete the enterprise database. A database connection file is simply a shortcut to the database.
0 Kudos
JoseSanchez
Occasional Contributor III

Hi,

This is what  I did:

if os.path.exists(sdeFile):

    # removing the file using the os.remove() method

    os.remove(sdeFile)

0 Kudos