This is the ASP.NET MVC 5 version of the MVC Music Store sample application.
- Visual Studio 2022 (or Visual Studio 2015 or later)
- SQL Server LocalDB - Installed with Visual Studio 2022
Note: SQL Server LocalDB is automatically installed with Visual Studio 2022 as part of the "ASP.NET and web development" workload or the "Data storage and processing" workload.
The MVC Music Store application uses SQL Server LocalDB with database files located in the App_Data folder:
MvcMusicStore.mdf- Main application databaseaspnet-MvcMusicStore-20131025034205.mdf- ASP.NET Identity database
The application is configured to automatically create and seed the database on first run:
- Open the solution in Visual Studio:
MvcMusicStore.sln - Build the solution (Ctrl+Shift+B)
- Run the application (F5)
The database will be automatically:
- Attached to LocalDB
- Initialized with the schema
- Seeded with sample music store data (albums, genres, artists)
This is handled by the SampleData class in Models/SampleData.cs, which is configured as the database initializer in Global.asax.cs and App_Start/Startup.App.cs.
If you need to manually connect to the database using Server Explorer in Visual Studio:
-
Open Server Explorer
- Go to
View>Server Explorer(or pressCtrl+Alt+S)
- Go to
-
Add a Data Connection
- Right-click
Data Connections>Add Connection…
- Right-click
-
Configure the Connection
- Data Source: Select
Microsoft SQL Server (SqlClient) - Server Name: Enter
(LocalDB)\MSSQLLocalDB - Authentication: Use
Windows Authentication - Database: Click
Browse…and select the.mdffile from theApp_Datafolder:- For the main database:
App_Data\MvcMusicStore.mdf - For the identity database:
App_Data\aspnet-MvcMusicStore-20131025034205.mdf
- For the main database:
- Data Source: Select
-
Confirm and Connect
- Click
OKto connect - Visual Studio will automatically attach the
.mdffile to LocalDB - You'll see the database listed under
Data Connectionsin Server Explorer
- Click
The application uses the following connection strings (configured in Web.config):
-
MusicStoreEntities: Main application database for albums, artists, and genres
Data Source=(LocalDb)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\MvcMusicStore.mdf; Integrated Security=True -
DefaultConnection: ASP.NET Identity database for user authentication
Data Source=(LocalDb)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\aspnet-MvcMusicStore-20131025034205.mdf; Initial Catalog=aspnet-MvcMusicStore-20131025034205; Integrated Security=True
The application automatically creates a default administrator account on startup:
- Username: Administrator
- Password: YouShouldChangeThisPassword
These credentials can be modified in Web.config:
<add key="DefaultAdminUsername" value="Administrator"/>
<add key="DefaultAdminPassword" value="YouShouldChangeThisPassword"/>If you encounter an error about LocalDB not being found:
- Verify LocalDB is installed by running in Command Prompt:
sqllocaldb info - If not installed, install it via Visual Studio Installer > Modify > Individual Components > SQL Server Express LocalDB
If you experience database connection issues:
- Delete the
.mdfand.ldffiles from theApp_Datafolder - Rebuild and run the application - the database will be recreated automatically
If the database is already attached to another instance:
- Detach it from Server Explorer (right-click the connection > Delete)
- Or use command line:
sqllocaldb stop MSSQLLocalDBandsqllocaldb start MSSQLLocalDB
- Open
MvcMusicStore.slnin Visual Studio - Press
F5to build and run the application - The application will open in your default browser
- Browse the music store, add items to cart, and test the checkout process
- Login with the administrator account to access the store management features
For more information about ASP.NET MVC, visit Microsoft Learn.