【发布时间】:2017-01-27 14:58:39
【问题描述】:
我正在尝试从 ASP.NET Core 1.0 Web 应用程序(Entity Framework Core)连接到 SQL Server 2014 或 2016。我收到以下错误。任何提示如何解决它。
我可以通过 Visual Studio 2015 SQL Server 对象资源管理器成功连接到数据库。但是,来自 Web 应用程序的连接失败。我也做不到dotnet ef database update。
我可以连接到 LOCALDB。
我的连接字符串如下所示:
"DefaultConnection": "Data Source=server;Initial Catalog=TestDb;Integrated Security=False;User ID=sa;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
我得到的错误是。我在 SQL Server 2014 和 2016 上遇到同样的错误:
An unhandled exception occurred while processing the request.
Win32Exception: The network path was not found
.ctor
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)
堆栈跟踪是:
Win32Exception: The network path was not found
.ctor
CreateConnection
CreatePooledConnection
CreateObject
UserCreateRequest
TryGetConnection
WaitForPendingOpen
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
GetResult
MoveNext in AccountController.cs
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
编辑 1
请注意,这不是同一个问题:为什么我收到"Cannot Connect to Server - A network-related or instance-specific error"?
编辑 2
我遇到问题的项目类型是 ASP.NET Core Web Application (.NET Core)。
但是我已经尝试创建 ASP.NET Core Web Application (.NET Framework) 项目并且那里没有问题。我能够连接。
你知道这些项目有什么不同吗?
【问题讨论】:
-
不,这不是重复的,也不是同一个问题。我可以从其他客户端连接到服务器,例如 VS2015 SQL Server Object Explorer 或 Serer Management Studio。但是我的 ASP.NET Core MVC Web 应用程序失败了。
-
您是否尝试过将连接字符串减少到最低限度?尝试使用
Data Source、Initial Catalog、User ID和Password参数,将所有其他参数排除在外。 -
不,减少连接字符串也没有帮助。
-
你可以试试下面的连接字符串吗?
Server=servername;Database=dbname;user=username;password=password;Trusted_Connection=False;
标签: sql-server asp.net-core entity-framework-core asp.net-core-1.0