title: Entity Framework and SQL Server database connection string
body: <p>I have worked with EF for a while now and i have always used LocalDb's for storing data. I want to start working with SQL Server databases instead but I'm having some issues setting up the connection string.</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx#sse" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx#sse</a>
  <a href="https://www.connectionstrings.com/" rel="nofollow noreferrer">https://www.connectionstrings.com/</a></p>
  
  <p>and looked over google but none of the answers made it work in my case so I must be doing something wrong (some of the connections strings throw an exception others didn't but wouldn't insert anything either into the database neither)</p>
  
  <p>My question is when working with EF &amp; SQL Server, should I use both the connection string in the <code>App.config</code> &amp; setting the path of the DB in the CTOR of the context (by using <code>AppDomain.CurrentDomain.SetData("DataDirectory", path);</code>) or is the <code>app.config</code> sufficient ? </p>
  
  <p>I have tried the following connection strings:</p>
  
  <pre><code>Data Source=.\GURUBEAST-PC\GURUSQL;Initial Catalog=iManager;Trusted_Connection=True;MultipleActiveResultSets=True;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;Database=iManager;Integrated Security=True;Trusted_Connection=True;MultipleActiveResultSets=True;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL11.GURUSQL\MSSQL\DATA\iManager.mdf;Database=iManager;Trusted_Connection=True;MultipleActiveResultSets=True;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL11.GURUSQL\MSSQL\DATA\iManager.mdf;Database=iManager;Trusted_Connection=True;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;Database=iManager;Trusted_Connection=True;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;Initial Catalog=iManager;Integrated Security=SSPI;
  
  Data Source=.\GURUBEAST-PC\GURUSQL;Initial Catalog=iManager;User id=GURUBEAST-PC\GuruBeast;
  </code></pre>
  
  <p>Where "iManager" is the name of the database. I use Windows auth for my SQL Server instance.</p>
  
  <p>What am I doing wrong ? Should I set my path to the program files folder or the <code>App_Data</code> (I have seen both and tried both but both didn't work)?</p>
  
  <p>Kind regards!</p>