title: Can't connect to local database using Visual studio
body: <p>I'm trying to connect to a local database in my project using Visual Studio. I made a local database file and added there some columns. </p>
  
  <p>To get into the database I tried the following code..
  (found it on the internet)</p>
  
  <pre><code>testcon = new System.Data.SqlClient.SqlConnection();
  testcon.ConnectionString = "Data Source=.\\SQLEXPRESS;" + "AttachDbFilename=|DataDirectory|DBtest.mdf;";
  testcon.ConnectionString += "database=dBtestDataSet;Integrated Security=True;Trusted_Connection=Yes;Connect Timeout=15";
  
  //open the connection       
  testcon.Open();
  MessageBox.Show("on");
  testcon.Close();
  MessageBox.Show("off");
  </code></pre>
  
  <p>The code works for the other people on the internet but I might do something wrong I think..</p>
  
  <p>The following error is that I received.</p>
  
  <blockquote>
    <p>SqlExeption was unhandled: An unhandled exception of type
    'System.Data.SqlClient.SqlException' occurred in System.Data.dll</p>
  </blockquote>
  
  <p>Image of my code with the solution explorer on the right and the database explorer on the left</p>
  
  <p><a href="http://i.imgur.com/MUAm1ty.png" rel="nofollow">http://i.imgur.com/MUAm1ty.png</a></p>
  
  <p>I hope someone can help me. I'll be very appreciated.</p>