A network-related or instance-specific error occurred while establishing a connection to SQL Server

Updated at:

This topic describes solutions to use when you cannot access an ApsaraDB RDS for SQL Server instance from an ECS instance over an internal network or from other devices over the internet.

Problem description

When you use an ECS instance to connect to an ApsaraDB RDS for SQL Server instance over an internal network, the following error message appears.

Cannot connect to XXX.
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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (Microsoft SQL Server, Error: 10060 or 258)

Solutions

Note

Note:

  • If you perform risky operations, such as modifying an instance or its data, ensure that the instance has disaster recovery and fault tolerance capabilities to protect your data.

  • Before you modify the configurations or data of instances, such as ECS and ApsaraDB RDS instances, create snapshots or enable features such as log backup.

  • If you have granted permissions or submitted security information, such as logon credentials, on the Alibaba Cloud platform, change them promptly.

An ECS instance cannot access an ApsaraDB RDS instance over an internal network

  1. Check if the internal IP address of the ECS instance is added to the whitelist of the ApsaraDB RDS instance.

    Before connecting to an ApsaraDB RDS instance using its internal endpoint, add the internal IP address of the ECS instance to the RDS whitelist. For more information, see How to query the IP address of an ECS instance and How to configure an RDS whitelist.

    Note

    If you only add the public IP address of the ECS instance to the RDS whitelist, you cannot connect to the ApsaraDB RDS instance over the internal network.

  2. Check if the ECS instance and the ApsaraDB RDS instance are in different regions.

    An ECS instance and an ApsaraDB RDS instance must be in the same region to connect over the internal network. They can be in the same or different zones within the same region.

    Click to view how to find the regions of the ApsaraDB RDS and ECS instances

    Go to the details page of the ApsaraDB RDS instance to view its region.

    image

    View the region of the ECS instance.

    image

    If the ECS instance and the ApsaraDB RDS instance are in different regions, they cannot connect directly over the internal network. You can use one of the following methods:

    • Method 1:

    • Method 2:

      Use the public endpoint of the ApsaraDB RDS instance to connect from the ECS instance. This method provides lower performance, security, and stability. For more information, see Request a public endpoint for an ApsaraDB RDS for SQL Server instance.

    • Method 3:

      Use Cloud Enterprise Network (CEN) to connect VPCs across regions. This method requires that both the source and destination instances use the VPC network type. For more information, see CEN overview.

  3. Check if the ECS and ApsaraDB RDS instances have the same network type. Both must be either virtual private cloud (VPC) or classic network.

    Click to view how to find the network types of the ApsaraDB RDS and ECS instances

    Go to the details page of the ApsaraDB RDS instance to view its network type.

    image

    View the network type of the ECS instance.

    image

    If the network types are different, use one of the following methods:

    Important

    The classic network type for Alibaba Cloud products is being phased out. For ApsaraDB RDS and ECS instances, switch from classic network to VPC as soon as possible. For more information, see [Product/Feature Change] Phasing out the classic network for ApsaraDB RDS databases and [Deprecation Notice] Discontinuation of services for classic network-type ECS instances.

  4. If both the ECS and ApsaraDB RDS instances are in VPCs, check if they are in different VPCs.

    Click to view how to find the VPC IDs of the ApsaraDB RDS and ECS instances

    View the VPC ID of the ApsaraDB RDS instance.

    image

    View the VPC ID of the ECS instance.

    image

    If they are in different VPCs, use one of the following methods:

  5. Check if the whitelist is set to 0.0.0.0. The correct format is 0.0.0.0/0.

    Important

    The entry 0.0.0.0/0 allows access from any IP address. This poses a security risk. Use it with caution.

  6. Check if the internal endpoint and port of the ApsaraDB RDS instance are correctly configured on the ECS instance. For more information, see View the internal and public endpoints and ports.

A device other than an ECS instance cannot access an ApsaraDB RDS instance

Note

When you access an ApsaraDB RDS instance, use its internal same-region endpoint instead of its IP address. The IP address may change if the instance is migrated.

Devices other than ECS instances can only connect to an ApsaraDB RDS instance over the internet. If the connection fails, use the following methods to resolve the issue.

  1. Check if you are using the internal endpoint of the ApsaraDB RDS instance.

    You must change the endpoint to the public endpoint of the ApsaraDB RDS instance. To obtain the public endpoint, see View the public endpoint.

    Note

    Devices other than ECS instances and DMS cannot access an ApsaraDB RDS instance over the internal network, unless you use an Express Connect circuit.

  2. Check if an RDS whitelist is configured. If not, see Configure a whitelist.

  3. Check if the whitelist is set to 0.0.0.0. The correct format is 0.0.0.0/0.

    Important

    The entry 0.0.0.0/0 allows access from any IP address. This poses a security risk. Use it with caution.

  4. If you have configured a whitelist but the connection still fails, the public IP address of your device that you added to the whitelist may not be the actual egress IP address. This can happen for the following reasons:

    • The public IP address is not fixed and may change.

    • The public IP address returned by an IP address query tool or website is inaccurate.

    Note

    To confirm the public IP address of your device, see How to determine the public IP address of an external server or client for SQL Server.

Applicable to

ApsaraDB RDS for SQL Server