VB.net-无法删除form.load上的sqlite文件

时间:2018-08-08 16:10:11

标签: vb.net sqlite

我有一个sqlite数据库,我想在form.load上删除它(在制作完副本之后)。我收到错误

“该进程无法访问该文件,因为该文件正在被另一个进程使用。

如果我在表单上创建一个按钮并运行相同的代码,它将删除该文件。

 '\\\\\\\ Copy old data into new database

        connect.Open()


        Dim attatch As String = "ATTACH '" + bklocation + "' as bkbackup"
        Dim fillspecinfo As String = "Insert into bkbackup.specinfo Select * from specinfo"
        Dim fillballcompany As String = " Insert into bkbackup.BallCompany select * from BallCompany"
        Dim fillbowlingballs As String = "Insert into bkbackup.BowlingBalls select * from BowlingBalls"
        Dim fillcustomerinfo As String = "Insert into bkbackup.CustomerInfo select * from CustomerInfo"
        Dim fillcustomernotes As String = "Insert into bkbackup.CustomerNotes select * from CustomerNotes"
        Dim fillremthumbid As String = "Insert into bkbackup.RemThumbID select * from RemThumbID"

        Dim cmd28 As SQLiteCommand = New SQLiteCommand(attatch, connect)
        Dim cmd29 As SQLiteCommand = New SQLiteCommand(fillspecinfo, connect)
        Dim cmd30 As SQLiteCommand = New SQLiteCommand(fillballcompany, connect)
        Dim cmd31 As SQLiteCommand = New SQLiteCommand(fillbowlingballs, connect)
        Dim cmd32 As SQLiteCommand = New SQLiteCommand(fillcustomerinfo, connect)
        Dim cmd33 As SQLiteCommand = New SQLiteCommand(fillcustomernotes, connect)
        Dim cmd34 As SQLiteCommand = New SQLiteCommand(fillremthumbid, connect)

        cmd28.ExecuteNonQuery()
        cmd29.ExecuteNonQuery()
        cmd30.ExecuteNonQuery()
        cmd31.ExecuteNonQuery()
        cmd32.ExecuteNonQuery()
        cmd33.ExecuteNonQuery()
        cmd34.ExecuteNonQuery()



    connect.Close()

    GC.Collect()
    GC.WaitForPendingFinalizers()

If connect.State = ConnectionState.Closed Then
    Try
        My.Computer.FileSystem.DeleteFile(dblocation)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
end If

在此问题上的任何帮助将不胜感激。谢谢

0 个答案:

没有答案