Skip to content

05 Change the Database Name

M. Fares edited this page Mar 12, 2018 · 1 revision

Q. How can I change the name of the database?

  1. Get the name of the connection string from the ApplicationDbContext constructor located in the /Models/IdentityModels.cs file
public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }
  1. The connection string is stored in the Web.Config file in the root folder of the project
<connectionStrings>
<add name="DefaultConnection" 
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20180304084410.mdf;Initial Catalog=aspnet-WebApplication1-20180304084410;Integrated Security=True"
providerName="System.Data.SqlClient" />
  </connectionStrings>
  1. Change the Initial Catalog=MyDatabase and AttachDbFilename=MyDatabase
  2. When you start your application, a new database will be created without your data

Clone this wiki locally