Wednesday, August 27, 2008
Home
.Net
Database tricks
Export to anything
DBCodeCreator.Net
Easy BigIron to IISAM
Flatfile fixer
Tips for datalinks
Neat security trick
Real BLOB examples
Jet locked?
All ISAMS are relational

Is that DB locked?

locked without actually connecting to the database, such as to do an administrative chore like a repair/compact or file backup.

 

In this circumstance, the IsDBOpenedExclusively(sPathToDB) routine documented in Microsoft's Jet Database Developer's Guide may be too much because it works by trying to make a connection and returns whether it could connect or not.  Why put the dbengine through all that work?

Consider, if you send a Jet database to Notepad and the file is not exclusively locked then the file will open as an ascii file.  However if you send a Jet file that is already opened exclusively to notepad you will receive a file permission error from the OS.  This tip routine builds off of that knowledge.  Just pass the database path to the function and check the return.

Public Function DBInUseExclusively(byval sPathToJetDB as string) As Boolean
   'by smith www.smithvoice.com
   'called when there is no lock file
   'just attempts to open the database and looks for
    a file permission denied error
   '
   'you should do a FileExist on the path
    prior to this function to head off 
   'invalid path statements, a good
   'one can be found at:   http://www.smithvoice.com/fileexis.aspx
    
   Dim FileNumber As Integer
   FileNumber = FreeFile
   On Error Resume Next
  
   Open sPathToJetDB For Input As FileNumber
  
   Close FileNumber
  
   If Err.Number = 70 Then
     DBInUseExclusively = True
     Err.Clear
   Else
     DBInUseExclusively = False
   End If
End Function

 

Try this on other lockable ISAMs for the same reasons.

Hope it helps.

Robert Smith
Kirkland WA

added to smithvoice july 1999


Print  

pagecomment
  Add Comment



Submit Comment
  View Comments
No comment.


Privacy Statement  |  Terms Of Use
Copyright 2008 by Robert C. Smith