0

I want the user to be able to move the sqlite file after the program already opened a connection with it:

Dim conn As New SQLite.SQLiteConnection()

conn.ConnectionString = connString

conn.Open()

But of course the program can't do that because file is being used by an other process. Closing the connection, calling conn.Dispose(), doesn't release the file.

So how can i release the file so then i can move it to an other location?

MauriF
  • 682
  • 6
  • 19
  • 1
    The code you have above has nothing to do with `moving a file`. I would assume the file is being accessed by the `SqliteConnection` class and locks this down, obviously locking access to it. ***but....*** it matters how you are **opening & closing/disposing** these objects as well; I have a good feeling your not cleaning up your objects. Could you please show us how you are making your connections and calls? – Trevor Apr 13 '16 at 13:41
  • Paying atention to what you said, i found out that i also needed to dispose the `SQLiteCommand` connection. Thank you! – MauriF Apr 13 '16 at 13:54
  • Welcome, wrap those in `Using` statements... This ensures they get disposed. – Trevor Apr 13 '16 at 13:56

1 Answers1

-1

Even after calling Dispose, there's a pointer internally that isn't released until the CLR's garbage collector runs. The file can't be moved until that happens. To force it, just run GC.Collect() after the Dispose.

Mike W.
  • 1,345
  • 8
  • 18
  • Detailed in this older post, but still very much true: https://stackoverflow.com/questions/8511901/system-data-sqlite-close-not-releasing-database-file – Mike W. Apr 13 '16 at 13:55