Link to home
Start Free TrialLog in
Avatar of cyyam
cyyam

asked on

Delete access .mdb problem

Hi,
In deleting .mdb file, I found that sometimes error occur:

permission denied


Is it because I have a corresponding .ldb file that keep some resources that the .mdb file is not allowed to delete?

I have tried to wait until it disappear after I disconnect the database.

If Dir(App.path & "\Database\" & appFileName & ".ldb") <> "" Then
        Do While True
            MsgBox "xx.ldb fading out..."
            DoEvents: Sleep 5000
            If Dir(App.path & "\Database\" & appFileName & ".ldb") = "" Then Exit Do
        Loop
   

But the .ldb never disappear!

What can i do?

1.Is my deduction correct, or is there any other points I have missed out?

2. And can first delete the .ldb file and then .mdb file? Please give me a sound solution ....

Thanks!

cyyam

Avatar of vinnyd79
vinnyd79

it sounds like you have an open connection to the database.Are you connecting to it from VB? Make sure you close the connection and set it to Nothing
Avatar of cyyam

ASKER

Can I just set it to nothing?
Does it mean already that the conn has been closed?
you could check it to see if it is Closed and set to Nothing:

If Not conn Is Nothing Then
    If conn.State <> adStateClosed Then conn.Close
    Set conn = Nothing
End If


you could also do the same for your recordsets.
The ldb element is the msaccess locking file. It will just reappear and dissapear.

The DBengine is the problem. It caches updated data and may not release the db until it has completed.

You should try the following

Assuming your object is mydb
mydb.close
set mydb=nothing
set dbengine=nothing

dbengine intialises when your app starts and does not close until your app closes

If it still persists you could try using another application to delete the db

x=shell("killer.app.exe",1)


A further thought

Are you using XP Office Pro across server 2000

If so there is currently an issue with all Office products causing locking contentions which could prevent you from deleting your db.
Yes,but aren't you assuming that DAO is being used rather than ADO?
Avatar of Mayank S
In case the connectoin with the VB program has been closed and the problem still persists, I hope that the file is not read-only!

Mayank.
u should close MDB file
if it's opened from acces u should close this access file


in this sub i want to compact access mdb file then delete old file and rename the new generated file to the old file name :
Sub CompactDB()
Dim DbName As String
DbName = Db2.Name
Db2.Close  ' here i close the database
Caption = "Compacting"
Dim X As String, DbFile As String, Dbpath As String
Dim pos As Long
X = DbName
pos = InStrRev(X, "\")
DbFile = Mid(X, pos + 1, Len(X))
Dbpath = Mid(X, 1, pos)
X = Dbpath & "XX" & DbFile
DBEngine.CompactDatabase DbName, X
Kill DbName
Name X As DbName
' here i re open the file
Set Db2 = DBEngine.OpenDatabase(App.Path & "\School.mdb")
End Sub
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- PAQ'd and points NOT refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

ayufans
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of AnnieMod
AnnieMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial