Failed to connect to Azure SQL Database

Shunlei Tang 140 Reputation points Microsoft Employee
2024-09-09T08:53:09.4366667+00:00

Got this error when establishing connection to Azure SQL Database:

Microsoft.Data.SqlClient.SqlException: 
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 - No such host is known.)
Inner Exception:
Win32Exception: No such host is known.

Here is the code:

using Microsoft.Data.SqlClient;

var builder = new SqlConnectionStringBuilder
{
    IPAddressPreference = SqlConnectionIPAddressPreference.IPv4First,
    //IPAddressPreference = SqlConnectionIPAddressPreference.IPv6First,
    DataSource = "<name_of_the_server>.database.windows.net",
    InitialCatalog = "<name_of_the_db>",
    Authentication = SqlAuthenticationMethod.ActiveDirectoryIntegrated,
    UserID = "<my_email>",
};

var connectionString = builder.ConnectionString;

using SqlConnection connection = new SqlConnection(connectionString);
connection.Open();

What's more, I also got similar error when connection through Azure Data Studio:

Microsoft.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: TCP Provider, error: 0 - No such host is known.

To make sure my IP is allowed by firewall, I manually added my IPv4 through Azure Portal and IPv6 through azure sql server ipv6-firewall-rule command. But things did not help, still got such error with either SqlConnectionIPAddressPreference.IPv4First or SqlConnectionIPAddressPreference.IPv6First.

I am 100% for sure that the target SQL server exists. What reason might it be and how to fix this?

Update: during this period, through "Metrics" section in Azure portal, the "Blocked by firewall" is constantly zero and "Availability (Preview)" is constantly 100%.

Azure SQL Database
{count} votes

Accepted answer
  1. Sai Raghunadh M 4,635 Reputation points Microsoft External Staff Moderator
    2024-09-09T14:27:50.4833333+00:00

    Hi@Shunlei Tang,

    Thanks for the question and using MS Q&A platform.

    could you please refer to the below mentioned document for more information that might help you in resolving your query.

    https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-11001-database-engine-error?view=sql-server-ver16

    For additional information, refer to this thread link: https://techcommunity.microsoft.com/t5/azure-database-support-blog/lesson-learned-244-no-such-host-is-known-connecting-to-azure-sql/ba-p/3662531#:~:text=A%20network-related%20or%20instance-specific%20error%20occurred%20while%20establishing,host%20is%20known.%29%20%28Microsoft%20SQL%20Server%2C%20Error%3A%2011001%29

    Hope this helps. Do let us know if you any further queries.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Abiola Akinbade 29,405 Reputation points Volunteer Moderator
    2024-09-09T08:58:41.9133333+00:00

    Can you use the troubleshooting steps here:

    https://learn.microsoft.com/en-us/troubleshoot/sql/database-engine/connect/network-related-or-instance-specific-error-occurred-while-establishing-connection#gather-information-for-troubleshooting-the-error

    That should help getting to the root cause.

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.