dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] SQlite Close connection

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    634

    Resolved [RESOLVED] SQlite Close connection

    Hello
    I've developed a small application in which I am using SQlite3 as backend and VB Rich Client framework.
    I have a problem of restoring the database.
    I'm using FileCopy to restore db.
    I can only do that without issue just after opening the application
    But I get permission denied error if I try to restore data after adding or deleting records.
    I seems the file is still in use though I close the connection before calling FileCopy
    Code:
    rs.close
    cnn.close
    thank you

  2. #2
    Hyperactive Member
    Join Date
    Jul 2013
    Posts
    372

    Re: SQlite Close connection

    There's no close method. I think you must set cnn to nothing to free it.
    Carlos

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,341

    Re: SQlite Close connection

    Quote Originally Posted by Carlos Rocha View Post
    There's no close method. I think you must set cnn to nothing to free it.
    Yep... neither the cRecordset - nor the cConnection-Object contain any .Close methods.

    It is sufficient, to set these Objects to Nothing, to free allocated memory or filehandles...

    So, the sequence to "overwrite the underlying File" (of a currently open cConnection in an opened App-Process) would be:
    - set all Recordsets to Nothing (which are potentially yet open, and were derived from an existing cConnection-instance)
    - after that set the cConnection-instance to Nothing
    - then do your FileCopy (to exchange the existing, current SQLite.db-file with your Backup-File)
    - reopen your cConnection-instance (on the File which was exchanged with the Backup-File)
    - reopen your Recordsets, refreshing the Forms which are currently open, and which were using these Rs

    HTH

    Olaf

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    634

    Re: SQlite Close connection

    There's no close method.
    Oh my bad!!!
    I know there is no Close method.
    in fact I was setting the Cconnection and the recordset to nothing.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    634

    Re: SQlite Close connection

    Quote Originally Posted by Schmidt View Post
    Yep... neither the cRecordset - nor the cConnection-Object contain any .Close methods.

    It is sufficient, to set these Objects to Nothing, to free allocated memory or filehandles...

    So, the sequence to "overwrite the underlying File" (of a currently open cConnection in an opened App-Process) would be:
    - set all Recordsets to Nothing (which are potentially yet open, and were derived from an existing cConnection-instance)
    - after that set the cConnection-instance to Nothing
    - then do your FileCopy (to exchange the existing, current SQLite.db-file with your Backup-File)
    - reopen your cConnection-instance (on the File which was exchanged with the Backup-File)
    - reopen your Recordsets, refreshing the Forms which are currently open, and which were using these Rs

    HTH

    Olaf
    I was following the same steps but still Permission denied error

    Code:
    Set RS = Nothing
    Set cnn = Nothing
    cd.ShowOpen
     PicFile = cd.fileName
    TxtData.Text = cd.Filetitle
    FileCopy (PicFile), App.Path & "\" & (TxtData.Text)
    Set cnn = New_c.Connection(DBPath)
    cnn.ReKey "123"
    cnn.OpenDB MyDBPath, "123"

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,341

    Re: SQlite Close connection

    Quote Originally Posted by samer22 View Post
    I was following the same steps but still Permission denied error
    Then you have other, still opened Recordsets (or CommandObjects, if you use them) in your App...

    For example in other Forms (which might be "Unloaded", but the Form-instance - including all its Private Vars -
    might still be alive... e.g. when you've shown the Form directly from its "Form-Name").

    In that case, you should set Form-local Rs-Variables to Nothing in Form_Unload,
    (or alternatively set the Rs.ActiveConnection to Nothing, shortly after opening a Recordset,
    or use "explicit Form-instancing" for modal- or other Forms, where you then set the Form-Variable itself to Nothing, after the Form was unloaded).

    HTH

    Olaf

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    634

    Re: SQlite Close connection

    Schmidt
    Thanks a million for these valuable info.
    Solved

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width