.Net Core 7 MVC SQL 连接错误提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接

问题描述 投票:0回答:1

我将 .net core 7 项目从一台计算机移至另一台计算机。我没有对代码进行任何更改。我也用同样的方式移动和恢复数据库。

但是,我无法打开我的项目并将其连接到sql server。我收到这样的错误:

Win32Exception: The network path was not found.
Unknown location

SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

我认为数据库没有问题,因为我能够创建一个虚拟控制台应用程序并成功连接到数据库并检索数据。

我尝试过的 我检查了两台机器上的.net版本 我检查了packagel的版本,卸载并重新安装。 尝试了不同的连接字符串

我认为问题出在应用程序中,因为当我尝试使用控制台应用程序时,我连接成功了

我的连接字符串:

"ConnectionStrings": {
    "db": "Server=localhost;Database=NIFBase;Trusted_Connection=True;"
  }

项目包:https://imgur.com/a/4qR0AQ6

c# .net sql-server .net-core asp.net-core-mvc
1个回答
-1
投票

您面临连接问题

创建数据库用户来访问您的数据库 并使用这个连接字符串

"ConnectionString": "Server=[SQL_SERVER_INSTANCE];Initial Catalog=[DATABASE_NAME];Persist Security Info=False;
        User ID=[DATABASE_USER];Password=[PASSWORD];MultipleActiveResultSets=False;
        Encrypt=True;TrustServerCertificate=False;Connection Timeout=3600;",
© www.soinside.com 2019 - 2024. All rights reserved.