python - File not being released -


ok have run queries in access 07 compact , repair it. using python , win32com this. code i'm using this.

import os; import win32com.client; db1 = 'db1.mdb' db2 = 'db1n.mdb' db3 = 'db2.mdb' dbr = r'db1.mdb' access = win32com.client.dispatch("access.application") access.opencurrentdatabase(dbr) db = access.currentdb() access.docmd.openquery("1") access.docmd.openquery("2") access.docmd.openquery("3") access.closecurrentdatabase() access.application.quit(); os.system('copy "db1.mdb" "db2.mdb"') access = win32com.client.dispatch("access.application") access.compactrepair(db3,db2) access.application.quit(); os.remove("db2.mdb") os.remove("db1.mdb") os.rename("db1n.mdb","db1.mdb") 

the problem error.

windowserror: [error 32] process cannot access file because being used process: 'db1.mdb' 

i dont know why getting error seeing quiting access should close file. idea how fix appreciated.

your code includes line:

db = access.currentdb() 

when line executes, currentdb() references db1.mdb. later windowserror at:

os.remove("db1.mdb") 

so i'm wondering if variable db still holds reference db1.mdb. perhaps first try del db before os.remove().

or, since code isn't using db variable, rid of it.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -