title: Access Denied While Connecting to local SQL database in Visual Studio 2010
body: <p>This is my code:</p>
  
  <pre><code>Console.WriteLine("Before Connect");
  SqlConnection myConnection = new SqlConnection(@"Server=.\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Database=Database;Trusted_Connection=Yes;");
  try
  {
      myConnection.Open();
      Console.WriteLine("After Connect");
  }
  catch (Exception e)
  {
      Console.WriteLine(e.ToString());
  }
  </code></pre>
  
  <p>And for some reason, it is giving me this error:</p>
  
  <blockquote>
    <p>A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in
    System.Data.dll
    System.Data.SqlClient.SqlException: Directory lookup for the file "C:\Users\Joe\Documents\Visual Studio 2010\Projects\FileIO\FileIO\bin\Debug\Database.mdf" failed with the operating system error 5(Access is denied.).</p>
  </blockquote>
  
  <p>Does anybody know how to fix this?</p>