Welcome to today’s blog.
In today’s post, I will be showing how to resolve a common error that I had recently when running a .NET Core application under the development environment.
The error is the SQL database creation error shown below:

The raw error is as shown:
.NET Core 4.6.26614.01 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.0.3-rtm-10026 | Microsoft Windows 10.0.18362 | Need help?System.Data.SqlClient.SqlException (0x80131904): Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\aspnet-BookLoan.mdf' because it already exists. Change the file path or the file name, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at
The .NET framework SQL Exception error is as shown:
Internal Server Error
An error occurred while starting the application.
SqlException: Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\aspnet-BookLoan.mdf' because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
To resolve tried the following:
- Check the connection string.
- Check the database exists within the SSMS databases.
If the database is not showing under the databases within SSMS then you will need to attach the database into your SQL Server host server.
Do this as follows:
Select Databases under your host server e.g. localhost. Select Attach…

Select the Database mdf file within your Data folder within the SQL Server installation subfolder:

Select Ok to attach.

Once done you will see the database in SSMS.
Expand and check it is accessible.

Now run the .NET Core application and the database will be accessible and the creation error will disappear.
That’s all for today’s post.
I hope this post has been useful and informative.

Andrew Halil is a blogger, author and software developer with expertise of many areas in the information technology industry including full-stack web and native cloud based development, test driven development and Devops.