title: Database connection and data saving in SQL Server
body: <p>I have SQL SERVER database file in Project folder. The same file copy in Debug folder. I attach these two files in SQL Server. File in project folder table contains Null value in all field. But there is data in the file attached from the Debug folder. I created the connection string with the file in Project folder. Actually which database file is the correct file? Try to solve this problem. </p>
  
  <p>The Connection String is</p>
  
  <pre><code>Public Conn As SqlConnection
  
  Public Function getConnect() As SqlConnection
  
      Conn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\EMP_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
  
      Return Conn
  
  End Function
  </code></pre>
  
  <p>And this is my code..</p>
  
  <pre><code> Try
              getConnect()
              Dim query As SqlCommand
              Dim strSQL As String
              strSQL = "INSERT INTO EMPLOYEE (EMP_ID,EMP_NAME,EMP_FNAME,EMP_GENDER,EMP_DOB,EMP_CAST,EMP_DEPART,EMP_DESIG,EMP_DOJ,EMP_SALARY,EMP_PF_ESI,EMP_BRANCH,EMP_CONTACT,EMP_ADDRESS)VALUES(@EMP_ID,@EMP_NAME,@EMP_FNAME,@EMP_GENDER,@EMP_DOB,@EMP_CAST,@EMP_DEPART,@EMP_DESIG,@EMP_DOJ,@EMP_SALARY,@EMP_PF_ESI,@EMP_BRANCH,@EMP_CONTACT,@EMP_ADDRESS)"
              query = New SqlCommand(strSQL, Conn)
              query.Parameters.Add(New SqlParameter("@EMP_ID", TXTEMPID.Text))
              query.Parameters.Add(New SqlParameter("@EMP_NAME", TXTNAME.Text))
              query.Parameters.Add(New SqlParameter("@EMP_FNAME", TXTFNAME.Text))
              query.Parameters.Add(New SqlParameter("@EMP_GENDER", gend))
              query.Parameters.Add(New SqlParameter("@EMP_DOB", DTPEMPDOB.Value.Date))
              query.Parameters.Add(New SqlParameter("@EMP_CAST", TXTCASTE.Text))
              query.Parameters.Add(New SqlParameter("@EMP_DEPART", CMBDEPT.Text))
              query.Parameters.Add(New SqlParameter("@EMP_DESIG", CMBDESIG.Text))
              query.Parameters.Add(New SqlParameter("@EMP_DOJ", DTPEMPDOJ.Value.Date))
              query.Parameters.Add(New SqlParameter("@EMP_SALARY", MTXTSAL.Text))
              query.Parameters.Add(New SqlParameter("@EMP_PF_ESI", MTXTPFESI.Text))
              query.Parameters.Add(New SqlParameter("@EMP_BRANCH", TXTBRANCH.Text))
              query.Parameters.Add(New SqlParameter("@EMP_CONTACT", MTXTCONTACT.Text))
              query.Parameters.Add(New SqlParameter("@EMP_ADDRESS", RTXTADDRESS.Text))
              Conn.Open()
              Dim numAffected = query.ExecuteNonQuery()
              'MessageBox.Show(numAffected)
              Conn.Close()
              If numAffected &gt; 0 Then
                  Call getConnect()
                  MessageBox.Show("Successfully Added", "Add", MessageBoxButtons.OK, MessageBoxIcon.Information)
                  BTNCLEAR.PerformClick()
              Else
                  MsgBox("No record was inserted")
              End If
          Catch ex As Exception
              MsgBox("ERROR: " + ex.Message, MsgBoxStyle.Information, "Add")
          End Try
      End If
  </code></pre>
  
  <p>I change my connection string like this...</p>
  
  <pre><code>Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\EMP_DB.mdf;Initial Catalog=EMP_DB;Integrated Security=True;Connect Timeout=30;User Instance=False
  </code></pre>