in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

"File in use by another process"...?

Last post 02-01-2010 4:28 PM by rkulp. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-01-2010 3:26 PM

    "File in use by another process"...?

     I'm writing in VB2008 Express on Vista Home Premium and I'm trying programatically to delete a database file that is no longer needed.  The code snippet is essentially:

     

            Dim SQLconnect As New SQLite.SQLiteConnection()
            SQLconnect.ConnectionString = "Data Source=" & dbname & ";"
            SQLconnect.Close()
            My.Computer.FileSystem.DeleteFile(dbname)

     The program throws the "file in use by another process" exception when trying to execute the last line shown.  'dbname' is the proper complete path.  Can anyone help me understand why this exception is being generated and what to do about it?

     

    TIA...

     

  • 02-01-2010 4:28 PM In reply to

    • rkulp
    • Top 10 Contributor
    • Joined on 06-28-2008
    • Rural Coffee County, Tennessee
    • Posts 73

    Re: "File in use by another process"...?

    I executed the following code without problem in Visual Studio 2005:

    Imports System.Data.SQLite

    Public Class Form1

    Dim realPath As String = "D:\VisualStudio2005\Projects\DeleteSQLiteDB\StartupDB.s3db"

    Dim dbConn As SQLiteConnection

    Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click

    Me.Close() End Sub

     

    Public Function CreateMyConnection() As SQLiteConnection

    Dim strConn As SQLiteConnectionStringBuilder = New SQLiteConnectionStringBuilder()

    With strConn

    .DataSource = Environment.ExpandEnvironmentVariables(realPath)

    .FailIfMissing = True

    End With

    Return New SQLiteConnection(strConn.ToString())

    End Function

    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

    dbConn = CreateMyConnection()

    dbConn.Open()

    Dim dbCmd As SQLiteCommand = New SQLiteCommand("SELECT * FROM Members", dbConn)

    dbCmd.CommandType = CommandType.Text

     

    End Sub

    Private Sub btnDeleteDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteDB.Click

    dbConn.Close()

    My.Computer.FileSystem.DeleteFile(realPath) End Sub

    End Class

    It seems there must be something else that has locked the file. 

     

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems