If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Is the database opened exclusively?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-02-10, 14:01
RedNeckGeek RedNeckGeek is offline
Village Idiot
 
Join Date: Jul 2003
Location: Michigan
Posts: 1,941
Is the database opened exclusively?

I have a db that I use as a datawarehouse. Every day, I dump all the data from the tables and reload it with current data from our legacy system. This gives users great access to customer and product data that they would otherwise have to hand key.

The users link those tables into their own databases, or sometimes run queries directly in the datawarehouse and export the results.

The problem I'm having is that once in a while a user will open the db with Open Exclusive.
Not only does this lock everyone out of the database, it locks up all databases linked to it.

My solution (because I don't want to go through the hassle of using security for it), was to
have a hidden form open on startup with code like this in the OnOpen event (granted, the code's not pretty yet, but it should be functional):

Code:
Private Sub Form_Open(Cancel As Integer)
  If IsDBOpenedExclusive(CurrentDb.Name) = True Then
    msgbox "Please do not open this db in exclusive mode"
    application.quit
  End If
End Sub

Function IsExclusive(strDbName As String) As Boolean
  'try to open the db again to see if we raise an error
  On Error Resume Next
  DBEngine.opendatabase (stDbName)

  ' If the database failed with error 3045,
  ' it was opened exclusively by someone else
  ' or possibly by ourselves.
  IsDBOpenedExclusive = (Err.Number = 3045)

End Function
Unfortunately, if I open the database exclusively, the above code fires, but doesn't throw an error.

Any idea what could be wrong? Is there another method I should use?
__________________
Inspiration Through Fermentation
Reply With Quote
  #2 (permalink)  
Old 09-03-10, 07:02
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,106
I did not try (in a hurry at the moment), but I would try to reopen the database in another workspace:
Code:
Set wrk = DBEngine.CreateWorkspace("", "admin", "")
set dbs = wrk.OpenDatabase (stDbName)
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 09-03-10, 07:59
RedNeckGeek RedNeckGeek is offline
Village Idiot
 
Join Date: Jul 2003
Location: Michigan
Posts: 1,941
Thanks for the reply, sinndho. Still no luck, though
__________________
Inspiration Through Fermentation
Reply With Quote
  #4 (permalink)  
Old 09-03-10, 18:30
DCKunkle DCKunkle is offline
Registered User
 
Join Date: Feb 2004
Location: Chicago, IL
Posts: 1,312
I was going to recommend trapping the error and then evaluating the error number when I noticed you are not returning the boolean value. Your function is IsExclusive but you are setting IsDBOpenedExclusive to a boolean value. Option Explicit strikes again.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On