Error SQL in appsettings.json string
I can't connect my project to the SQL Server Local instance. Even after configuring the connection string in appsettings.json, it doesn't work when running the dotnet ef database update command.
I've tried various methods:
- Using Windows credentials gives an error saying it’s not supported.
- Using the default sa credentials also fails.
Error:
PS $dotnet ef database update
Build started...
Build succeeded.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database '' on server 'DESKTOP-2222222'.
An error occurred using the connection to database '' on server 'DESKTOP-2222222'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10404]
Build started...
Build succeeded.
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database '' on server 'DESKTOP-2222222'.
An error occurred using the connection to database '' on server 'DESKTOP-2222222'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10404]
3 Replies
.NET is a marketing term referring to a family of products, consisting of two different lineages.
The .NET Framework ("netfx") lineage was introduced in 2002. This lineage runs only on Windows. Its most recent release is .NET Framework 4.8.1. While this lineage is still supported, very few new features are being introduced into it. Devs are encouraged not to target .NET Framework for new app development.
The .NET Core ("netcore") lineage was introduced in 2016. This is a modern development platform which runs across many different OSes. The .NET Core 3.1 product was the last version in this lineage to bear the ".NET Core" name; and starting with the next release (.NET 5), the product was renamed to simply ".NET".
.net6
in 2021, .net7
in 2022, .net8
in 2023 ... the next release in this lineage is .NET 9. This lineage is where new features are actively being developed. Devs are encouraged to target .NET for new app development.
Nowadays, the ".NET" moniker usually refers to recent versions of the netcore lineage. When you create a new app targeting .NET (not .NET Framework!), you're targeting this newer, modern, cross-platform API surface and runtime.Does EF Core work fine in your application? Or it is only migrations related issue?
I would recommend to check how you configure EF Core and store connection string. Check this https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings?tabs=dotnet-core-cli
Connection Strings - EF Core
Managing connection strings under different environments with Entity Framework Core
It worked! The issue was with the string storage and DBContext, thx!