.Net Core 2.0与EF7连接到SQL Server Express.错误:26 - 找到服务器/实例时出错

Kir*_*eed 5 entity-framework-core .net-core

我正在尝试连接到在2003服务器上运行的2008R2 SQLEXPRESS实例.

我可以使用Server Explorer从我的.net core 2.0项目中连接到数据库

我可以运行用.net框架编写的连接数据库的程序.

但是当我尝试从我的.net核心项目中连接时,我收到以下错误

System.Data.SqlClient.SqlException (0x80131904): 
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)
at System.Data.SqlClient.SqlInternalConnectionTds. etc
Run Code Online (Sandbox Code Playgroud)

问题不在于连接字符串的格式,因为它适用于数据库的本地备份.

连接字符串在appsettings.json中类似于

"ConnectionStrings": {
"MyDatabase": "Server=MySERVER\\SQLEXPRESS;Database=mydatabase;Trusted_Connection=False;User=sa;password=mypassword"
Run Code Online (Sandbox Code Playgroud)

SQL Server Browser已启动.我可以通过Management Studio访问数据

我没有运行SQL Server代理.当我尝试启动它时,我会在事件记录器中看到

SQLServerAgent could not be started (reason: This installation of SQL Server 
Agent is disabled.  The edition of SQL Server that installed this service
does not support SQL Server Agent.).
Run Code Online (Sandbox Code Playgroud)

Kir*_*eed 1

我已经能够通过使用连接字符串中的端口号而不是实例名称来解决此问题。

正如这里所建议的

并找到我可以使用的端口

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on' 
GO
Run Code Online (Sandbox Code Playgroud)