dcsimg
Results 1 to 4 of 4

Thread: Cannot delete sqlite db file from Form_load

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    5

    Cannot delete sqlite db file from Form_load

    So I will try to keep this short.

    I updated the database with new fields, so I want to create a new sqlite db and dump the previous data into the new db and rename it.

    I have tried every possible way I know how to close, dispose, GC.collect, etc, and will not let go of the old .db file. If I make a button on the form and copy the code to delete, it will work. Just for some reason in the form_load screen, it wont let go of it.


    Code:
     Using connect1 As New SQLiteConnection(Datasource)
                connect1.Open()
    
               ' Clear all textboxes
    
                Dim a As Control
                For Each a In Me.AddPanel.Controls
                    If TypeOf a Is TextBox Then
                        a.Text = Nothing
                    End If
                Next
    
                MaskedTextBox1.Text = ""
    
    
    
                    'Update Combobox with Ball Companies
    
                    Dim adapter As String = ("Select * from BallCompany order by Company")
                    Dim cmd9 As SQLiteCommand = New SQLiteCommand(adapter, connect1)
                    cmbxBBall.Items.Clear()
                    Dim dr = cmd9.ExecuteReader
    
                    While dr.Read
    
                        cmbxBBall.Items.Add(dr("Company"))
                        ComboBox3.Items.Add(dr("Company"))
                
    
                    End While
                    dr.Close()
    
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
    
                End Try
    
    
    
                Call dgv6fill()
    
                connect1.Close()
    
    
            End Using
    
            GC.Collect()
            GC.WaitForPendingFinalizers()
    
    
            IO.File.Delete(dblocation)

    returns the error
    System.IO.IOException
    HResult=0x80070020
    Message=The process cannot access the file 'C:\ProgramData\Spec Sheet Keeper\proshopDB.db' because it is being used by another process.
    Source=mscorlib
    StackTrace:
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.InternalDelete(String path, Boolean checkHost)
    at System.IO.File.Delete(String path)
    at WindowsApp1.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\jf.ARC\source\repos\ProshopPanels\WindowsApp1\Forms\Form1.vb:line 440
    at System.EventHandler.Invoke(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
    at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
    at System.Windows.Forms.Control.set_Visible(Boolean value)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at WindowsApp1.My.MyApplication.Main(String[] Args) in :line 81



    ANY ANY help would be appreciated. I have tried clearing all pools also, and nothing seems to work. BTW if something looks weird with my coding, please let me know, I am a System Admin by trade, learning how to code.

    Thanks for your time

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,890

    Re: Cannot delete sqlite db file from Form_load

    Try...
    Code:
    Using cmd9 As SQLiteCommand... Etc
    .   'your code
    End Using
    'delete file after all using blocks close
    Instead of...

    Code:
    Dim cmd9 As SQLiteCommand

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    5

    Re: Cannot delete sqlite db file from Form_load

    Quote Originally Posted by .paul. View Post
    Try...
    Code:
    Using cmd9 As SQLiteCommand... Etc
    .   'your code
    End Using
    'delete file after all using blocks close
    Instead of...

    Code:
    Dim cmd9 As SQLiteCommand
    I implemented that into the code but that is not the only thing that was hanging onto the file. It was the sub call. Once I made your change and commented out the call, it worked.

    Thank you for your help. Its more appreciated than you know.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,890

    Re: Cannot delete sqlite db file from Form_load

    When you call a sub procedure, you don't need the Call keyword. It's a leftover from legacy times...

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