简体   繁体   English

.NET Core API 无法连接到 MS LocalDB

[英].NET Core API cannot connect to MS LocalDB

I am writing a .NET Core 2.1 web API using MS LocalDB.我正在使用 MS LocalDB 编写 .NET Core 2.1 Web API。 I can connect to my DB fine using SSMS and the server name (localdb)\\MSSQLLocalDB with Windows Authentication.我可以使用 SSMS 和带有 Windows 身份验证的服务器名称(localdb)\\MSSQLLocalDB连接到我的数据库。

The API fails to connect with the error: API 连接失败,错误如下:

A network-related or instance-specific error occurred while establishing a connection to SQL Server.与 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.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. (提供程序:SQL 网络接口,错误:50 - 发生本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。

My connection string is:我的连接字符串是:

Server=(localdb)\\MSSQLLocalDB;Database=Foo;Trusted_Connection=True;MultipleActiveResultSets=true

As a side note, I tried to check my LocalDB version with sqllocaldb v but got the following error:作为旁注,我尝试使用sqllocaldb v检查我的 LocalDB 版本,但出现以下错误:

Windows API call "RegGetValueW" returned error code: 0.

Is my LocalDB installation completely borked?我的 LocalDB 安装完全无聊吗?

its kinda late but i am trying this for 2 days and finally found the answer.有点晚了,但我尝试了 2 天,终于找到了答案。

  1. When app is running on IIS --> go to advance setting in the application pool, then on change "Process Model->Load Profile" to TRUE;当应用程序在 IIS 上运行时 --> 转到应用程序池中的高级设置,然后将“进程模型->负载配置文件”更改为 TRUE;

  2. when app is running on Kestrel, a.当应用程序在 Kestrel 上运行时, connection string "Data Source=(localdb)\\mssqllocaldb"... etc连接字符串“数据源=(localdb)\\mssqllocaldb”...等

hope this help the others.希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM