【发布时间】:2021-12-13 06:25:45
【问题描述】:
我正在尝试为我的 ASP.NET Core Web 应用程序设置一个数据库。不幸的是,每次我尝试运行 dotnet ef Database Update 时,都会收到此错误:
Error Number:-1983577829,State:0,Class:20
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 50 - Local Database Runtime err
or occurred. Specified LocalDB instance name is invalid.)
我已经尝试了所有我能想到的方法,并多次重新安装。我已经安装了带有 LocalDB 的 Visual Studio 2019、带有 LocalDB 的 2022、单独安装了 LocalDB、带有 LocalDB 的 SQLExpress,但这一切都没有奏效。我什至重置了我的电脑,但遗憾的是它仍然没有改变任何东西。
这是我的连接字符串:
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=PROJECT_NAME_HERE;Trusted_Connection=True;MultipleActiveResultSets=true"
我正在使用连接字符串:
services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
});
我应该提一下,这个连接字符串过去一直有效。 任何帮助,将不胜感激!谢谢:D
【问题讨论】:
-
确保你的连接字符串是正确的,好像
(localdb)\\mssqllocaldb不是一个有效的实例。