Have you tried changing your database name? You can use something like (Look at your appsettings.json file or web.config file)
<add name="DefaultConnection" connectionString="Server=YourDatasource;Database=DatabaseNameAsYouWish;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
If you use SQL Management Studio, you will find the Data Source Connection string while you are connecting to the database. Copy and paste it, then try again. If it works, let me know, please.
Edit: Setup Connection String for ASP.NET Core 5 Web API Project
Step 1:
For ASP.NET Core 5, in the appsettings.json
file, put the connection string
"ConnectionStrings": {
"sqlConnection": "Server=YourServerName;Database=YourDatabaseName;Integrated Security=true; Trusted_Connection=True;"
},
(Note: If you want to use localdb, the connection string would be
"ConnectionStrings": {
"sqlConnection": "Server=(localdb)\\mssqllocaldb;Database=YourDatabaseName;Trusted_Connection=True;"
},
)
Where to find Server name?
- Open SQL Server Management Studio
- In the Server name field, if you do not see the server name listed, click Browse for more...
- Click the + sign next to Database Engine and you will see your Server name. Click on the server name and select it. Now connect to your SQL Server.
Now connect to your SQL Server.
Step 2.
In the startup.cs
add the service in the ConfigureServices(IServiceCollection services){ place your sql connectiono service here }
method
// DatabaseContext comes from DatabaseContext.cs
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("sqlConnection")) // sqlConnection comes from appSettings connectionString
);