Results 1 to 4 of 4

Thread: [VB6 RC6 SQLite] cConnection.OpenDB : Internally what happens if already open?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    [VB6 RC6 SQLite] cConnection.OpenDB : Internally what happens if already open?

    Example:



    Code:
    'In a Global module
    Public Cnn As cConnection
    Set Cnn = New cConnection
    
    
    
    'In a form method
    Cnn.OpenDB (App.Path & "\TLSDB\tools.db")
    If the database has already been opened prior to coming to ...

    Code:
    Cnn.OpenDB (App.Path & "\TLSDB\tools.db")
    ... in another form method, no error occurs.

    The code just sails through as if nothing is wrong.

    So my question is (drumroll!): Is there a sort of "Open DB if not open, otherwise ignore the error" going on inside .OpenDB?

    And if so, would it be good practice (or insurance) to simply add the .OpenDB() in methods that will be accessing the DB to insure no error of a closed DB occurs? No cost insurance?

    TIA

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,066

    Re: [VB6 RC6 SQLite] cConnection.OpenDB : Internally what happens if already open?

    Quote Originally Posted by webbiz View Post
    If the database has already been opened prior to coming to ...

    Code:
    Cnn.OpenDB (App.Path & "\TLSDB\tools.db")
    ... in another form method, no error occurs.
    Why would you expect an error?

    The Cnn.OpenDB-call allows to Open (or Re-Open) "another DB-File" on an existing Cnn-instance.
    (involving a proper cleanup of a potentially already pre-existing SQLite-DBFile-Handle beforehand).

    You apparently decided, to do a "re-open" on the Cnn with the same DB-Filename for some reason...

    Quote Originally Posted by webbiz View Post
    ... would it be good practice (or insurance) to simply add the .OpenDB() in methods that will be accessing the DB to insure no error of a closed DB occurs?
    No, good practice would be, to learn how to utilize Sub Main() as the "single entry-point into your App" -
    wherein you can initialize and open all your "global Object-Variables" exactly once.

    Olaf
    Last edited by Schmidt; Sep 28th, 2023 at 01:08 AM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [VB6 RC6 SQLite] cConnection.OpenDB : Internally what happens if already open?

    Quote Originally Posted by Schmidt View Post
    Why would you expect an error?

    The Cnn.OpenDB-call allows to Open (or Re-Open) "another DB-File" on an existing Cnn-instance.
    (involving a proper cleanup of a potentially already pre-existing SQLite-DBFile-Handle beforehand).

    You apparently decided, to do a "re-open" on the Cnn with the same DB-Filename for some reason...



    No, good practice would be, to learn how to utilize Sub Main() as the "single entry-point into your App" -
    wherein you can initialize and open all your "global Object-Variables" exactly once.

    Olaf
    Why expect an error? Not sure other than I had thought trying to open an already opened DB would produce one, much like trying to open a file that is already open (or in use).

    Okay, back to Main() it is. I'll keep that in mind. Thanks.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,884

    Re: [VB6 RC6 SQLite] cConnection.OpenDB : Internally what happens if already open?

    Quote Originally Posted by webbiz View Post
    Why expect an error? Not sure other than I had thought trying to open an already opened DB would produce one, much like trying to open a file that is already open (or in use).
    That would sort of defeat the purpose of database files, no?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width