title: Switch from LocalDB to SQL Server DB MVC5
body: <p>I have a MVC5 project with individual authentication. </p>
  
  <p>Now I want to move from <code>(localdb)\MSSQLLocalDB</code> to another SQL Server database.</p>
  
  <p>I've tried to change connection string from this :</p>
  
  <pre><code>Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;Connect
  Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>Data Source=PC-GABRI;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
  </code></pre>
  
  <p>And the application is still using localDB instead of my new SQL Server DB.</p>
  
  <p>I have already migrated the database and roles.</p>
  
  <p>I have also tried to comment all of my connection string form <code>Web.Config</code> but my application is still working and I can login with my "test" user.</p>
  
  <p>I can't find anything on the web about this!</p>
  
  <p>PS.</p>
  
  <p>Related Questions: <a href="https://stackoverflow.com/questions/45651634/switch-localdb-to-sql-server-db-with-mvc5/54947332#54947332">Switch LocalDB to SQL server db with MVC5</a></p>
  
  <p>We have the same problem!</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>DB Instance:</p>
  
  <p><a href="https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/" rel="nofollow noreferrer"><img src="https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/" alt="Database Instances"></a></p>
  
  <p>Connection String:</p>
  
  <p><a href="https://i.stack.imgur.com/O6JLU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O6JLU.png" alt="enter image description here"></a></p>
  
  <p>The instances are running correctly.</p>
  
  <p>Tell me if you need more info.</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>This Guide was very useful for me : </p>
  
  <p><a href="https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/" rel="nofollow noreferrer">https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/</a></p>
  
  <p>Follow all the easy steps for move your LocalDB table to SQL server db Table.</p>
  
  <p><strong>1.  Inspect the Web.config File Connection String and Connect to Local Database</strong></p>
  
  <p>Change the defaut connection string:</p>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApp-20190226025646.mdf;Initial Catalog=aspnet-WebApp-20190226025646;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>To your connection string:</p>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Data Source=PC-YWGSB;Initial Catalog=WebApp;user id=admin;password=admin" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p><strong>2. Then use the commands for DB Migration "Codefirst"</strong></p>
  
  <p>This is the official guide:</p>
  
  <p><a href="https://docs.microsoft.com/it-it/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application" rel="nofollow noreferrer">https://docs.microsoft.com/it-it/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application</a></p>
  
  <p><em>From the Tools menu, select NuGet Package Manager > Package Manager Console.
  At the PM> prompt enter the following commands:</em></p>
  
  <blockquote>
    <ol>
    <li>enable-migrations </li>
    <li>add-migration InitialCreate</li>
    <li>update-database</li>
    </ol>
  </blockquote>
  
  <p>The database will be created automatically during migration. 
  If you already have one make sure to backup all tables.</p>