How to detect if database has been opened by another user?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: How to detect if database has been opened by another user?

  1. #1
    Chris L. Guest

    How to detect if database has been opened by another user?


    How do I go about detecting whether another user has opened up a database
    connection?

    I'm using ado 2.5 to connect to an Access 2000 database and I'm wanting to
    detect if another user has opened a connection with the database. If so,
    the other person will not be permitted to open the database. So essentially,
    it's a networked single user application. Odd yes, but the situation calls
    for this sort of app.

    Thanks,
    Chris

  2. #2
    George Shubin Guest

    Re: How to detect if database has been opened by another user?

    > How do I go about detecting whether another user has opened up a database
    > connection?


    Before your program opens the database, call this function:

    Function AreWeAlone(sDir As String, sDatabaseName As String) As Integer
    Dim sFile As String
    'Determine if there are any other users accessing the database.
    'If the LDB file is not present, then nobody is accessing it.
    'sDir should end with a '\'
    'sDatabaseName should not end with a file extension like '.MDB'
    AreWeAlone = True
    On Error GoTo Alone_Error
    If Right(sDir,1) <> "\" Then sDir = sDir & "\"
    sFile = UCase(Dir(sDir & sDatabaseName & ".ldb"))
    If sFile = UCase(sDatabaseName & ".LDB" Then AreWeAlone = False
    End_of_Alone:
    On Error GoTo 0
    Exit Function
    Alone_Error:
    'MsgBox "The database is already in use by another user." + Chr(13) +
    Chr(13) + Error$ + CStr(Err)
    AreWeAlone = False
    Resume End_of_Alone
    End Function




    --
    ------------------------------------------------------------------------
    George Shubin Custom Software Development
    DX Software Systems Database Applications
    Ph: 503-981-6806 Fax: 503-982-0120
    www.dxonline.com dx@dxonline.com
    ------------------------------------------------------------------------




  3. #3
    marc Guest

    Re: How to detect if database has been opened by another user?


    Just one addition: The existence of a .ldb field does not neccessarily mean
    someone else has the database open. If the last person accessed the database
    by a query in another database, the .ldb file does not get removed after
    the query is closed. At least in Access 97.

    Marc

    "George Shubin" <dx@dxonline.com> wrote:
    >> How do I go about detecting whether another user has opened up a database
    >> connection?

    >
    >Before your program opens the database, call this function:
    >
    >Function AreWeAlone(sDir As String, sDatabaseName As String) As Integer
    > Dim sFile As String
    > 'Determine if there are any other users accessing the database.
    > 'If the LDB file is not present, then nobody is accessing it.
    > 'sDir should end with a '\'
    > 'sDatabaseName should not end with a file extension like '.MDB'
    > AreWeAlone = True
    > On Error GoTo Alone_Error
    > If Right(sDir,1) <> "\" Then sDir = sDir & "\"
    > sFile = UCase(Dir(sDir & sDatabaseName & ".ldb"))
    > If sFile = UCase(sDatabaseName & ".LDB" Then AreWeAlone = False
    > End_of_Alone:
    > On Error GoTo 0
    >Exit Function
    >Alone_Error:
    > 'MsgBox "The database is already in use by another user." + Chr(13)

    +
    >Chr(13) + Error$ + CStr(Err)
    > AreWeAlone = False
    > Resume End_of_Alone
    >End Function
    >
    >
    >
    >
    >--
    >------------------------------------------------------------------------
    >George Shubin Custom Software Development
    >DX Software Systems Database Applications
    >Ph: 503-981-6806 Fax: 503-982-0120
    >www.dxonline.com dx@dxonline.com
    >------------------------------------------------------------------------
    >
    >
    >



  4. #4
    Mark Jerde Guest

    Re: How to detect if database has been opened by another user?

    Is there any way to force the DB to only be opened in exclusive mode? I
    know of no way, but someone else might....

    -- Mark

    "Chris L." <clintvedt@ifcu.com> wrote in message
    news:3b8fe697$1@news.devx.com...
    >
    > How do I go about detecting whether another user has opened up a database
    > connection?
    >
    > I'm using ado 2.5 to connect to an Access 2000 database and I'm wanting to
    > detect if another user has opened a connection with the database. If so,
    > the other person will not be permitted to open the database. So

    essentially,
    > it's a networked single user application. Odd yes, but the situation calls
    > for this sort of app.
    >
    > Thanks,
    > Chris




  5. #5
    JD Guest

    Re: How to detect if database has been opened by another user?


    "Mark Jerde" <jerde@sanspamcompuserve.com> wrote:
    >Is there any way to force the DB to only be opened in exclusive mode? I
    >know of no way, but someone else might....
    >


    This will open the database exclusively through code always, If you want
    to force it through Access itself I do not know.

    With cnnDB
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Mode = adModeShareExclusive
    .Open strDBPath
    End With

    JD


  6. #6
    Paul Clement Guest

    Re: How to detect if database has been opened by another user?

    On 31 Aug 2001 12:33:43 -0700, "Chris L." <clintvedt@ifcu.com> wrote:


    How do I go about detecting whether another user has opened up a database
    connection?

    I'm using ado 2.5 to connect to an Access 2000 database and I'm wanting to
    detect if another user has opened a connection with the database. If so,
    the other person will not be permitted to open the database. So essentially,
    it's a networked single user application. Odd yes, but the situation calls
    for this sort of app.


    You might want to try the Jet utilities:

    http://support.microsoft.com/support.../Q176/6/70.ASP


    Paul ~~~ pclement@ameritech.net
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center