Introduce support for "Command Timeout" connection property (#1765)

This commit is contained in:
Cheena Malhotra
2023-01-03 21:42:32 -08:00
committed by GitHub
parent 376f6e6008
commit a8f9219f09
6 changed files with 90 additions and 4 deletions

View File

@@ -101,6 +101,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
GroupName = "Initialization"
},
new ConnectionOption
{
Name = "commandTimeout",
DisplayName = "Command timeout",
Description =
"The length of time (in seconds) to wait for a command to complete on the server before terminating the attempt and generating an error",
ValueType = ConnectionOption.ValueTypeNumber,
DefaultValue = "30",
GroupName = "Initialization"
},
new ConnectionOption
{
Name = "currentLanguage",
DisplayName = "Current language",

View File

@@ -1403,6 +1403,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
connectionBuilder.ConnectTimeout = connectionDetails.ConnectTimeout.Value;
}
if (connectionDetails.CommandTimeout.HasValue)
{
connectionBuilder.CommandTimeout = connectionDetails.CommandTimeout.Value;
}
if (connectionDetails.ConnectRetryCount.HasValue)
{
connectionBuilder.ConnectRetryCount = connectionDetails.ConnectRetryCount.Value;
@@ -1554,6 +1558,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
ConnectRetryCount = builder.ConnectRetryCount,
ConnectRetryInterval = builder.ConnectRetryInterval,
ConnectTimeout = builder.ConnectTimeout,
CommandTimeout = builder.CommandTimeout,
CurrentLanguage = builder.CurrentLanguage,
DatabaseName = builder.InitialCatalog,
ColumnEncryptionSetting = builder.ColumnEncryptionSetting.ToString(),
@@ -1731,11 +1736,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
// capture original values
int? originalTimeout = connInfo.ConnectionDetails.ConnectTimeout;
int? originalCommandTimeout = connInfo.ConnectionDetails.CommandTimeout;
bool? originalPersistSecurityInfo = connInfo.ConnectionDetails.PersistSecurityInfo;
bool? originalPooling = connInfo.ConnectionDetails.Pooling;
// increase the connection timeout to at least 30 seconds and and build connection string
// increase the connection and command timeout to at least 30 seconds and and build connection string
connInfo.ConnectionDetails.ConnectTimeout = Math.Max(30, originalTimeout ?? 0);
connInfo.ConnectionDetails.CommandTimeout = Math.Max(30, originalCommandTimeout ?? 0);
// enable PersistSecurityInfo to handle issues in SMO where the connection context is lost in reconnections
connInfo.ConnectionDetails.PersistSecurityInfo = true;
// turn off connection pool to avoid hold locks on server resources after calling SqlConnection Close method
@@ -1747,6 +1754,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
// restore original values
connInfo.ConnectionDetails.ConnectTimeout = originalTimeout;
connInfo.ConnectionDetails.CommandTimeout = originalCommandTimeout;
connInfo.ConnectionDetails.PersistSecurityInfo = originalPersistSecurityInfo;
connInfo.ConnectionDetails.Pooling = originalPooling;

View File

@@ -233,6 +233,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
}
}
/// <summary>
/// Gets or sets the length of time (in seconds) to wait for a command to complete on the server before terminating the attempt and generating an error.
/// </summary>
public int? CommandTimeout
{
get
{
return GetOptionValue<int?>("commandTimeout");
}
set
{
SetOptionValue("commandTimeout", value);
}
}
/// <summary>
/// The number of reconnections attempted after identifying that there was an idle connection failure.
/// </summary>
@@ -608,6 +624,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
&& ConnectRetryCount == other.ConnectRetryCount
&& ConnectRetryInterval == other.ConnectRetryInterval
&& ConnectTimeout == other.ConnectTimeout
&& CommandTimeout == other.CommandTimeout
&& string.Equals(CurrentLanguage, other.CurrentLanguage, System.StringComparison.InvariantCultureIgnoreCase)
&& string.Equals(DatabaseDisplayName, other.DatabaseDisplayName, System.StringComparison.InvariantCultureIgnoreCase)
&& string.Equals(DatabaseName, other.DatabaseName, System.StringComparison.InvariantCultureIgnoreCase)

View File

@@ -30,6 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
HostNameInCertificate = details.HostNameInCertificate,
PersistSecurityInfo = details.PersistSecurityInfo,
ConnectTimeout = details.ConnectTimeout,
CommandTimeout = details.CommandTimeout,
ConnectRetryCount = details.ConnectRetryCount,
ConnectRetryInterval = details.ConnectRetryInterval,
ApplicationName = details.ApplicationName,