title: How to solve this . The process cannot access the file
body: <p>The process cannot access the file 'F:\copy back up\system\HRM 2-5-2013\HRM\HRM\lanbased.txt' because it is being used by another process.
  This is my code in sub main</p>
  
  <pre><code>Public localhost As String
  Public username As String
  Public port As String
  Public database As String
  Public conn As New MySqlConnection
  Public NAME1 As String = "F:\copy back up\system\HRM 2-5-2013\HRM\HRM\lanbased.txt"
  
  Public Sub main()
      Dim frm As New Form1
      Dim frm1 As New create
  
      If System.IO.File.Exists(NAME1) = True Then
          Try
              Dim objReader As New System.IO.StreamReader(NAME1)
  
              localhost = objReader.ReadLine() &amp; vbNewLine
              username = objReader.ReadLine() &amp; vbNewLine
              port = objReader.ReadLine() &amp; vbNewLine
              database = objReader.ReadLine() &amp; vbNewLine
              conn.ConnectionString = "server=" &amp; Trim(localhost) &amp; ";user id=" &amp; Trim(username) &amp; "; password=" &amp; Trim(port) &amp; "; database=" &amp; Trim(database) &amp; ""
              conn.Open()
  
  
              Application.Run(New Form1())
          Catch ex As Exception
              MsgBox("Unable  to connect to database", vbCritical)
  
              Application.Run(New create())
          End Try
      End If
      Exit Sub
  End Sub
  </code></pre>
  
  <p>and this is my code in my form create.
  How do I access the file when it is being used by another process?</p>
  
  <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim FILE_NAME As String = "F:\copy back up\system\HRM 2-5-2013\HRM\HRM\lanbased.txt"
  
      If TextBox1.Text = Nothing Or TextBox2.Text = Nothing Or TextBox3.Text = Nothing Or TextBox4.Text = Nothing Then
          MsgBox("fill up mo pa ngot")
  
      ElseIf System.IO.File.Exists(FILE_NAME) = True Then
  
          Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
  
  
          objWriter.Write(TextBox1.Text + vbCrLf)
          objWriter.Write(TextBox2.Text + vbCrLf)
          objWriter.Write(TextBox3.Text + vbCrLf)
          objWriter.Write(TextBox4.Text + vbCrLf)
          objWriter.Close()
  
          TextBox1.Clear()
          TextBox2.Clear()
          TextBox3.Clear()
          TextBox4.Clear()
  
      ElseIf conn.State = True Then
  
          MsgBox("maka connect naka")
  
      End If
  End Sub
  </code></pre>