title: Attaching SQL Server Express DB using VB.Net Code
body: <p>I am using the following VB code to attach my DBs to server.</p>
  
  <pre><code>Dim cnnConnection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" &amp; Application.StartupPath + "\datafiles\" + TextBox1.Text + ".mdf" &amp; ";Integrated Security=True;Database='" &amp; TextBox1.Text &amp; "';Connect Timeout=30")
      cnnConnection.Open()
  </code></pre>
  
  <p>But it gives an error:</p>
  
  <p>Unable to open the physical file "D:.Net Programs\SQLDBAttachExperiments\SQLDBAttachExperiments\bin\Debug\datafiles\dbSQLtest.mdf". Operating system error 5: "5(error not found)". Cannot attach the file 'D:.Net Programs\SQLDBAttachExperiments\SQLDBAttachExperiments\bin\Debug\datafiles\dbSQLtest.mdf' as database 'dbSQLtest'.</p>
  
  <p>How to fix it?
  Thanks</p>