在 visual studio 2019 年无法连接到 SQL Server Express

Unable to connect to SQL Server Express in visual studio 2019

我正在尝试使用迁移连接到我的 SQL Server Express。迁移成功,但更新时出现错误。

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

appsetings.json

{
"Logging": {
"LogLevel": {
  "Default": "Information",
  "Microsoft": "Warning",
  "Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DemoLoginContextConnection": "Server=(DESKTOP-48LBLF\SQLEXPRESS)\mssqllocaldb;Database=DemoLogin;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

SSMS

如您的屏幕截图所示 - server/instance 名称应该只是 DESKTOP-48LBLF\SQLEXPRESS - 而不是您现在拥有的名称....

试试这个:

"ConnectionStrings": {
    "DemoLoginContextConnection": "Server=DESKTOP-48LBLF\SQLEXPRESS;Database=DemoLogin;Trusted_Connection=True;MultipleActiveResultSets=true"
}