"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=ABC; Trusted_Connection=True; MultipleActiveResultSets=true"}
我正在使用ASP.NET Core MVC。我在appsettings.json文件中有这个连接字符串,但它似乎不起作用。从cmd运行“dotnet ef数据库更新”时,我收到不支持此错误的关键字:'server。'。它出什么问题了?
道歉!在Startup.cs中的ConfigureServices方法中,我使用的是SQLite数据库提供程序
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")))
我将其更改为以下内容,并且它与我的连接字符串一起使用。
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")))
连接字符串应该以Data Source=
开头。
在Visual Studio中,如果打开SQL Server对象资源管理器并单击要连接的数据库。连接字符串将显示在“属性”窗口中。对于localDb,连接字符串看起来应该是这样的
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DbName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=Fals