Skip to content

Commit bc8474f

Browse files
authored
Merge pull request #18149 from MicrosoftDocs/master
12/21 AM Publish
2 parents e5664d2 + f966208 commit bc8474f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

docs/connect/jdbc/connecting-to-an-azure-sql-database.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Connecting to an Azure SQL database"
33
description: "This article discusses issues when using the Microsoft JDBC Driver for SQL Server to connect to an Azure SQL Database."
44
ms.custom: ""
5-
ms.date: "08/12/2019"
5+
ms.date: "12/18/2020"
66
ms.prod: sql
77
ms.prod_service: connectivity
88
ms.reviewer: ""
@@ -27,7 +27,7 @@ This article discusses issues when using the [!INCLUDE[jdbcNoVersion](../../incl
2727
## Details
2828

2929
When connecting to an [!INCLUDE[ssAzure](../../includes/ssazure_md.md)], you should connect to the master database to call **SQLServerDatabaseMetaData.getCatalogs**.
30-
[!INCLUDE[ssAzure](../../includes/ssazure_md.md)] doesn't support returning the entire set of catalogs from a user database. **SQLServerDatabaseMetaData.getCatalogs** use the sys.databases view to get the catalogs. Please refer to the discussion of permissions in [sys.databases (Transact-SQL)](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md) to understand **SQLServerDatabaseMetaData.getCatalogs** behavior on an [!INCLUDE[ssAzure](../../includes/ssazure_md.md)].
30+
[!INCLUDE[ssAzure](../../includes/ssazure_md.md)] doesn't support returning the entire set of catalogs from a user database. **SQLServerDatabaseMetaData.getCatalogs** use the sys.databases view to get the catalogs. Refer to the discussion of permissions in [sys.databases (Transact-SQL)](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md) to understand **SQLServerDatabaseMetaData.getCatalogs** behavior on an [!INCLUDE[ssAzure](../../includes/ssazure_md.md)].
3131

3232
## Connections dropped
3333

@@ -37,7 +37,13 @@ When connecting to an [!INCLUDE[ssAzure](../../includes/ssazure_md.md)], idle co
3737

3838
- Idle by the Azure SQL Gateway, where TCP **keepalive** messages might be occurring (making the connection not idle from a TCP perspective), but not had an active query in 30 minutes. In this scenario, the Gateway will determine that the TDS connection is idle at 30 minutes and terminate the connection.
3939

40-
To avoid dropping idle connections by a network component, the following registry settings (or their non-Windows equivalents) should be set on the operating system where the driver is loaded:
40+
To address the second point and avoid the Gateway terminating idle connections, you can:
41+
42+
* Use the **Redirect** [connection policy](/azure/azure-sql/database/connectivity-architecture#connection-policy) when configuring your Azure SQL data source.
43+
44+
* Keep connections active via lightweight activity. This method is not recommended and should only be used if there are no other possible options.
45+
46+
To address the first point and avoid dropping idle connections by a network component, the following registry settings (or their non-Windows equivalents) should be set on the operating system where the driver is loaded:
4147

4248
|Registry Setting|Recommended Value|
4349
|----------------------|-----------------------|
@@ -47,7 +53,13 @@ To avoid dropping idle connections by a network component, the following registr
4753

4854
Restart the computer for the registry settings to take effect.
4955

50-
To accomplish this when running in Azure create a startup task to add the registry keys. For example, add the following Startup task to the service definition file:
56+
The KeepAliveTime and KeepAliveInterval values are in milliseconds. These settings will have the effect of disconnecting an unresponsive connection within 10 to 40 seconds. After a keep alive packet is sent, if no response is received, it will be retried every second up to 10 times. If no response is received during that time, the client-side socket is disconnected. Depending on your environment, you may want to increase the KeepAliveInterval to accommodate known disruptions (like virtual machine migrations) that might cause a server to be unresponsive for longer than 10 seconds.
57+
58+
> [!NOTE]
59+
> TcpMaxDataRetransmissions is not controllable on Windows Vista or Windows 2008 and higher.
60+
61+
To perform this configuration when running in Azure, create a startup task to add the registry keys. For example, add the following Startup task to the service definition file:
62+
5163

5264
```xml
5365
<Startup>
@@ -56,7 +68,7 @@ To accomplish this when running in Azure create a startup task to add the regist
5668
</Startup>
5769
```
5870

59-
Then add a AddKeepAlive.cmd file to your project. Set the "Copy to Output Directory" setting to Copy always. The following is a sample AddKeepAlive.cmd file:
71+
Then add a AddKeepAlive.cmd file to your project. Set the "Copy to Output Directory" setting to Copy always. The following script is a sample AddKeepAlive.cmd file:
6072

6173
```bat
6274
if exist keepalive.txt goto done
@@ -85,4 +97,4 @@ jdbc:sqlserver://abcd.int.mscds.com;databaseName=myDatabase;user=myName;password
8597

8698
## See also
8799

88-
[Connecting to SQL Server with the JDBC driver](connecting-to-sql-server-with-the-jdbc-driver.md)
100+
[Connecting to SQL Server with the JDBC driver](connecting-to-sql-server-with-the-jdbc-driver.md)

0 commit comments

Comments
 (0)