Blog Post

Azure Database Support Blog
3 MIN READ

Lesson Learned #472:Why It's Important to Add the TCP Protocol When Connecting to Azure SQL Database

Jose_Manuel_Jurado's avatar
Jan 11, 2024

In certain service requests, our customers encounter the following error while connecting to the database, similar like this one: "Connection failed: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [65]. (65) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if the instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (65)'. I would like to give some insights about this.

 

The crucial point to mention is that Azure SQL Database only responds to TCP, and any attempt to use Named Pipes will result in an error.

 

1. Understanding the Error Message:

  • The error message encountered by our customer is typically associated with attempts to connect using the Named Pipes protocol, which Azure SQL Database does not support. It signifies a network-related or instance-specific error in establishing a connection to SQL Server, often caused by incorrect protocol usage.

2. Azure SQL Database's Protocol Support:

  • Azure SQL Database is designed to work exclusively with the TCP protocol for network communication. TCP is a reliable, standard network protocol that ensures the orderly and error-checked transmission of data between the server and client.

3. Why Specify TCP in Connection Strings:

  • Specifying "TCP:" in the server name within your connection strings ensures that the client application directly attempts to use the TCP protocol. This bypasses any default attempts to use Named Pipes, leading to a more straightforward and faster connection process.

4. Error Diagnosis and Efficiency:

  • By using TCP, any connectivity issues encountered will return errors specific to the TCP protocol, making diagnosis more straightforward. This direct approach eliminates the time spent on protocol negotiation and reduces the time to connect.

5. Recommendations for Azure SQL Database Connectivity:

  • Always use TCP in your connection strings when connecting to Azure SQL Database.
  • Ensure that your client and network configuration are optimized for TCP/IP connectivity.
  • Regularly update your ODBC drivers and client software to the latest versions to benefit from improved performance and security features.

6. Prioritizing TCP to Avoid Unnecessary Delays in Connectivity:

  • An important aspect to consider in database connectivity is the order in which different protocols are attempted by the client or application. Depending on the configuration, the client may try to connect using Named Pipes before or after TCP in the event of a connectivity issue. This can lead to unnecessary delays in the validation process.
  • When Named Pipes is attempted first and fails (as it is unsupported in Azure SQL Database), the client then falls back to TCP, thereby wasting valuable time. This scenario is particularly common when default settings are left unchanged in client applications or drivers.
  • To mitigate this, it is strongly recommended to explicitly use "TCP:" in the server name within your connection strings. This directive ensures that the TCP protocol is prioritized from the outset, facilitating a more direct and efficient connection attempt.
  • By doing so, not only do we avoid the overhead of an unsuccessful attempt with Named Pipes, but we also gain clarity in error reporting. If a connectivity issue arises, the error returned will be specific to TCP, allowing for a more accurate diagnosis and faster resolution.
  • Additionally, this approach can significantly reduce the time taken to establish a connection. In high-performance environments or situations where rapid scaling is required, this efficiency can have a substantial impact on overall system responsiveness and resource utilization.
  • In summary, explicitly specifying the TCP protocol in your connection strings is a best practice for Azure SQL Database connectivity. It ensures a more streamlined connection process, clearer error diagnostics, and can contribute to overall system efficiency.

 

Enjoy!

Published Jan 11, 2024
Version 1.0
  • m60freeman's avatar
    m60freeman
    Brass Contributor

    Is there any value in changing the Connection Properties in SSMS from "<default>" to "TCP/IP" when connection to Azure SQL Databases, or does SSMS detect that TCP/IP is the only supported protocol and uses it without changing this value?