Asp.net mvc 连接字符串在ASP.NET核心中不起作用

Asp.net mvc 连接字符串在ASP.NET核心中不起作用,asp.net-mvc,asp.net-core,Asp.net Mvc,Asp.net Core,我正在使用ASP.NET核心MVC。我在appsettings.json文件中有这个连接字符串,但它似乎不起作用。从cmd运行“dotnet ef database update”时,我遇到了以下错误:关键字不受支持:“服务器”。。有什么问题吗?连接字符串应该以数据源=开头 在Visual Studio中,如果打开SQL Server对象资源管理器并单击要连接到的数据库。连接字符串将显示在“属性”窗口中。对于localDb,connections字符串应该是这样的 "ConnectionStri

我正在使用ASP.NET核心MVC。我在appsettings.json文件中有这个连接字符串,但它似乎不起作用。从cmd运行“dotnet ef database update”时,我遇到了以下错误:关键字不受支持:“服务器”。。有什么问题吗?

连接字符串应该以
数据源=
开头

在Visual Studio中,如果打开SQL Server对象资源管理器并单击要连接到的数据库。连接字符串将显示在“属性”窗口中。对于localDb,connections字符串应该是这样的

"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=ABC; Trusted_Connection=True; MultipleActiveResultSets=true"}

连接字符串应以
数据源=
开头

在Visual Studio中,如果打开SQL Server对象资源管理器并单击要连接到的数据库。连接字符串将显示在“属性”窗口中。对于localDb,connections字符串应该是这样的

"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=ABC; Trusted_Connection=True; MultipleActiveResultSets=true"}

抱歉!在Startup.cs中的ConfigureServices方法中,我使用的是SQLite数据库提供程序

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DbName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=Fals
services.AddDbContext(options=>options.UseSqlite(Configuration.GetConnectionString(“DefaultConnection”))
我将其更改为以下内容,并使用我的连接字符串

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")))
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”))

抱歉!在Startup.cs中的ConfigureServices方法中,我使用的是SQLite数据库提供程序

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DbName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=Fals
services.AddDbContext(options=>options.UseSqlite(Configuration.GetConnectionString(“DefaultConnection”))
我将其更改为以下内容,并使用我的连接字符串

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")))
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”))

假设您使用EntityFramework进行此连接是真的吗?这不是EF连接,可能与@Nkosi重复,我知道,这就是为什么我试图知道OP是否使用EF来解释错误。是的,我使用EFIs假设是真的,您正在为此连接使用EntityFramework?这不是EF连接字符串@Nkosi的可能副本,我知道,这就是为什么我试图知道OP是否将其与EF一起使用,这将解释错误。是的,我正在使用EF