.Net Core 2.0 与 EF7 连接到 SQL Server Express.错误:26 - 定位服务器/实例时出错 [英] .Net Core 2.0 with EF7 connecting to SQL Server Express. Error: 26 - Error Locating Server/Instance

查看:34
本文介绍了.Net Core 2.0 与 EF7 连接到 SQL Server Express.错误:26 - 定位服务器/实例时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to connect to an 2008R2 SQLEXPRESS instance that is running on a 2003 server.

我可以使用服务器资源管理器从我的 .net core 2.0 项目中连接到数据库

I can connect to the database from within my .net core 2.0 project using Server Explorer

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

I can run programs written in .net framework that connect to the database.

但是,当我尝试从 .net 核心项目中进行连接时,出现以下错误

However when I try to connect from within my .net core project I get the following error

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

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

The problem is not the format of the connection string because it works on a local back up of the database.

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

The connection string is in appsettings.json similar to

"ConnectionStrings": {
"MyDatabase": "Server=MySERVER\SQLEXPRESS;Database=mydatabase;Trusted_Connection=False;User=sa;password=mypassword"

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

SQL Server Browser is started . I can access the data via Management Studio

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

I am not running SQL Server Agent. When I try and start it I see in the event logger

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.).

推荐答案

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

I have been able to work around by using the port number in the connection string instead of the instance name.

根据建议此处

并找到我可以使用的端口

And to find the port I can use

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on' 
GO

这篇关于.Net Core 2.0 与 EF7 连接到 SQL Server Express.错误:26 - 定位服务器/实例时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆