Menu

Why is SingleConnection=true not locking the .mdb file?

Help
Gerrit
2016-11-28
2016-12-04
  • Gerrit

    Gerrit - 2016-11-28

    Hi,
    can someone explain me why this connection:

    conn = DriverManager.getConnection("jdbc:ucanaccess://" + dBPath + ";SingleConnection=true;Openexclusive=true;ignorecase=true");
    

    is not preventing an second instance of the application from accessing the .mdb file?

    The first instance is not calling conn.close(); & there is an created <dbname>.ldb file in the DB folder.
    Any ideas about this?

     
  • Gord Thompson

    Gord Thompson - 2016-11-28

    Hi Gerrit. Two things:

    1. It's not "singleConnection" that would put a lock on a database file, it's "openExclusive" that would be expected to do it. (In recent versions of UCanAccess, "immediatelyReleaseResources" has replaced "singleConnection" as the preferred option name because the "singleConnection" name was confusing.)

    2. UCanAccess behaves a bit differently from Access when it comes to "exclusive access". If one UCanAccess process already has the database open with "openExclusive" then a second UCanAccess process will not be prevented from opening the database altogether, it will simply be forced to read-only mode.

     
  • Gerrit

    Gerrit - 2016-11-29

    Thank you very much gordon, it makes it much clearer.
    Now everything is so easy:
    if(conn.isReadOnly()){//To Do}

     

    Last edit: Gerrit 2016-11-29
  • RavenAtSafe

    RavenAtSafe - 2016-12-02

    What version of UCanAccess adds the (much better named) "immediatelyReleaseResources" alias for "singleConnection"? The main website still talks about the latter.

     
    • Gord Thompson

      Gord Thompson - 2016-12-02

      Hi Raven. The new name was introduced in v3.0.6.

      Thanks for the reminder about the website. (Marco: I have updated the "Connection Properties" section of site.html.)

       
  • Marco Amadei

    Marco Amadei - 2016-12-04

    I forgot this documentation, thank you!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.