title: Incorrect connection string? Error: An attempt to attach an auto-named database failed
body: <p>Solution: Add the directory to your connection string in the app.config file and the Settings.setting file in the properties section of your project. My working connection string ended up being <code>&lt;Value Profile="(Default)"&gt;Data Source=(LocalDB)\v11.0;AttachDbFilename=F:\hi\prgrm\ProgramName\Database1.mdf;Integrated Security=True&lt;/Value&gt;</code></p>
  
  <p>Once I run my program I get the following error:</p>
  
  <blockquote>
    <p>An attempt to attach an auto-named database for file F:\Graded unit
    2\SimplyRugby\LollipopUI\bin\Debug\Database1.mdf failed. A
    database with the same name exists, or specified file cannot be
    opened, or it is located on UNC share.</p>
  </blockquote>
  
  <p>The method that makes the error happen:</p>
  
  <pre><code>public bool CheckUsername(string username)
  {
      var usernameResult = (from person in dbContext.Persons
                              where (person.Username == username)
                              select person.Username).FirstOrDefault(); 
                            //stores username if a username is found
  
      return !(string.IsNullOrEmpty(usernameResult));
      // if no correct user found from query return false else true
  }
  </code></pre>
  
  <p>After some research apparently it's that the connection string is wrong. I had a little play with some suggestions online but I'm not too sure what is incorrect and how to fix it so I've been going around in circles for the past five or so hours.</p>
  
  <p>My <code>app.config</code> file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;connectionStrings&gt;
          &lt;add name="LollipopUI.Properties.Settings.Database1ConnectionString"
               connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;"
               providerName="System.Data.SqlClient" /&gt;
      &lt;/connectionStrings&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Thank you for your time.</p>