带有EF7的.Net Core 2.0连接到SQL Server Express。错误:26-查找服务器/实例时出错 [英] .Net Core 2.0 with EF7 connecting to SQL Server Express. Error: 26 - Error Locating Server/Instance

查看:260
本文介绍了带有EF7的.Net Core 2.0连接到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

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

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