Getting error: A network-related or instance-specific error occurred while establishing a connection to SQL Server
Getting error: A network-related or instance-specific error occurred while establishing a connection to SQL Server
我是开发新手。我在尝试从我的计算机连接到 SQL 服务器时遇到问题。
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)
我搜索了发布方式,找到了很多解决方案。但是 none 正在为我工作。你能帮帮我吗?
这是我的连接字符串
string constring = @"Data Source=137.xx.xx.xxx\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
和
string constring = @"Data Source=CISXXXXXX\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
最后,这些是一些对我不起作用的解决方案的参考:
- https://www.lansweeper.com/kb/174/a-network-related-or-instance-specific-error-occurred.html
- https://support.solarwinds.com/Success_Center/Network_Performance_Monitor_(NPM)/Exception_A_network_related_or_instance_specific_error_while_establishing_a_connection_to_SQL_Server
- Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?
- Why did a network-related or instance-specific error occur while establishing a connection to SQL Server?
试试这个:
string constring = @"Data Source=137.xx.xx.xxx\SQLEXPRESS;Initial Catalog=EDI_HR;Integrated Security =True";
这是一个非常普遍的错误,您可能需要多次尝试才能解决它。
检查从应用程序计算机到数据库计算机的连接。打开命令行,首先尝试使用 ping 和 telnet "ping 137.xx.xx.xxx"、"ping CISXXXXXX"、"telnet 137.xx.xx.xxx 1433"、"telnet CISXXXXXX 1433"。如果您没有连接,那么有两种主要可能性:
- 未配置到该 IP 的路由;
- SQL 服务器端口被两侧或中间的防火墙关闭。也许这些地址甚至是路由器(不是实际的数据库机器)并且没有为端口 1433 设置 NAT。
转到远程计算机并尝试在本地连接到名为 SQLEXPRESS
的 SQL 服务器实例(使用 SSMS)。如果你不能,也许它还没有开始。或者可能没有命名实例,您需要连接到默认实例(即不指定 SQLEXPRESS
)
检查 SQL 服务器实例是否允许通过 TCP/IP 进行远程连接。我想最简单的方法是转到远程计算机并打开 SQL 服务器配置管理器。
检查连接字符串中的符号。我看到您的连接字符串之一有双反斜杠,另一个有单反斜杠。那是可疑的。如果您从 @ 开始 C# 字符串文字,那么您应该使用单反斜杠。
还有其他可能性,但我想你明白了。
您不必使用 .\SQLEXPRESS,您只需添加您的 SQL 快递名称即可,它适用于我
<add name="BlogDbContext" connectionString="data source=your name here; initial catalog=CodeFirstDemo; integrated security=True" providerName="System.Data.SqlClient"/>
在与您的远程服务器建立连接时,
尝试在服务器末尾使用“\SQLEXPRESS”。
示例:"ABCD_server_name\SQLEXPRESS"
尝试在连接字符串中使用端口号而不是实例名称
As I explain here
如果您遇到以下错误:
Connection error in SSMS
那么有两种方法。
- 创建连接时,请确保 SSMS 中的实例名称正确。 SQL 服务器和 SSMS 中的实例名称必须相同。
服务器名称:(your-pc-name)(instance-name)。
转到“运行”并键入命令“services.msc”。然后搜索 SQL 服务器 (instance-name)。在“服务器名称”中使用此实例名称。
[万一这个方法不行]
- 在安装SQL服务器时,如果您选择“基本”选项,请从“服务器名称”中删除实例名称。只需使用您的系统名称作为服务器名称即可。
我是开发新手。我在尝试从我的计算机连接到 SQL 服务器时遇到问题。
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)
我搜索了发布方式,找到了很多解决方案。但是 none 正在为我工作。你能帮帮我吗?
这是我的连接字符串
string constring = @"Data Source=137.xx.xx.xxx\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
和
string constring = @"Data Source=CISXXXXXX\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
最后,这些是一些对我不起作用的解决方案的参考:
- https://www.lansweeper.com/kb/174/a-network-related-or-instance-specific-error-occurred.html
- https://support.solarwinds.com/Success_Center/Network_Performance_Monitor_(NPM)/Exception_A_network_related_or_instance_specific_error_while_establishing_a_connection_to_SQL_Server
- Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?
- Why did a network-related or instance-specific error occur while establishing a connection to SQL Server?
试试这个:
string constring = @"Data Source=137.xx.xx.xxx\SQLEXPRESS;Initial Catalog=EDI_HR;Integrated Security =True";
这是一个非常普遍的错误,您可能需要多次尝试才能解决它。
检查从应用程序计算机到数据库计算机的连接。打开命令行,首先尝试使用 ping 和 telnet "ping 137.xx.xx.xxx"、"ping CISXXXXXX"、"telnet 137.xx.xx.xxx 1433"、"telnet CISXXXXXX 1433"。如果您没有连接,那么有两种主要可能性:
- 未配置到该 IP 的路由;
- SQL 服务器端口被两侧或中间的防火墙关闭。也许这些地址甚至是路由器(不是实际的数据库机器)并且没有为端口 1433 设置 NAT。
转到远程计算机并尝试在本地连接到名为
SQLEXPRESS
的 SQL 服务器实例(使用 SSMS)。如果你不能,也许它还没有开始。或者可能没有命名实例,您需要连接到默认实例(即不指定SQLEXPRESS
)检查 SQL 服务器实例是否允许通过 TCP/IP 进行远程连接。我想最简单的方法是转到远程计算机并打开 SQL 服务器配置管理器。
检查连接字符串中的符号。我看到您的连接字符串之一有双反斜杠,另一个有单反斜杠。那是可疑的。如果您从 @ 开始 C# 字符串文字,那么您应该使用单反斜杠。
还有其他可能性,但我想你明白了。
您不必使用 .\SQLEXPRESS,您只需添加您的 SQL 快递名称即可,它适用于我
<add name="BlogDbContext" connectionString="data source=your name here; initial catalog=CodeFirstDemo; integrated security=True" providerName="System.Data.SqlClient"/>
在与您的远程服务器建立连接时, 尝试在服务器末尾使用“\SQLEXPRESS”。 示例:"ABCD_server_name\SQLEXPRESS"
尝试在连接字符串中使用端口号而不是实例名称 As I explain here
如果您遇到以下错误: Connection error in SSMS
那么有两种方法。
- 创建连接时,请确保 SSMS 中的实例名称正确。 SQL 服务器和 SSMS 中的实例名称必须相同。 服务器名称:(your-pc-name)(instance-name)。 转到“运行”并键入命令“services.msc”。然后搜索 SQL 服务器 (instance-name)。在“服务器名称”中使用此实例名称。
[万一这个方法不行]
- 在安装SQL服务器时,如果您选择“基本”选项,请从“服务器名称”中删除实例名称。只需使用您的系统名称作为服务器名称即可。