diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs
index 56972809c0..6634b4e840 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs
@@ -22,7 +22,7 @@ public ConnectionDetails() : base()
///
/// Gets or sets the connection password
///
- public string Password
+ public string Password
{
get
{
@@ -155,7 +155,7 @@ public string? Encrypt
get
{
string? value = GetOptionValue("encrypt");
- if(string.IsNullOrEmpty(value))
+ if (string.IsNullOrEmpty(value))
{
// Accept boolean values for backwards compatibility.
value = GetOptionValue("encrypt")?.ToString();
@@ -503,7 +503,7 @@ public int? Port
{
SetOptionValue("port", value);
}
- }
+ }
///
/// Gets or sets a string value that indicates the type system the application expects.
@@ -540,7 +540,7 @@ public string ConnectionString
///
/// Gets or sets the group ID
///
- public string GroupId
+ public string GroupId
{
get
{
@@ -555,7 +555,7 @@ public string GroupId
///
/// Gets or sets the database display name
///
- public string DatabaseDisplayName
+ public string DatabaseDisplayName
{
get
{
@@ -566,7 +566,7 @@ public string DatabaseDisplayName
SetOptionValue("databaseDisplayName", value);
}
}
-
+
public string AzureAccountToken
{
get
@@ -591,32 +591,47 @@ public int? ExpiresOn
}
}
+ ///
+ /// Compares all SQL Server Connection properties to be able to identify differences in current instance and provided instance appropriately.
+ ///
+ /// Instance to compare with.
+ /// True if comparison yeilds no differences, otherwise false.
public bool IsComparableTo(ConnectionDetails other)
- {
- if (other == null)
- {
- return false;
- }
-
- if (ServerName != other.ServerName
- || AuthenticationType != other.AuthenticationType
- || UserName != other.UserName
- || AzureAccountToken != other.AzureAccountToken)
- {
- return false;
- }
-
- // For database name, only compare if neither is empty. This is important
- // Since it allows for handling of connections to the default database, but is
- // not a 100% accurate heuristic.
- if (!string.IsNullOrEmpty(DatabaseName)
- && !string.IsNullOrEmpty(other.DatabaseName)
- && DatabaseName != other.DatabaseName)
- {
- return false;
- }
-
- return true;
- }
+ => other != null
+ && string.Equals(ApplicationIntent, other.ApplicationIntent, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(ApplicationName, other.ApplicationName, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(AttachDbFilename, other.AttachDbFilename, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(AuthenticationType, other.AuthenticationType, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(AzureAccountToken, other.AzureAccountToken, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(ColumnEncryptionSetting, other.ColumnEncryptionSetting, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(ConnectionString, other.ConnectionString, System.StringComparison.InvariantCultureIgnoreCase)
+ && ConnectRetryCount == other.ConnectRetryCount
+ && ConnectRetryInterval == other.ConnectRetryInterval
+ && ConnectTimeout == other.ConnectTimeout
+ && string.Equals(CurrentLanguage, other.CurrentLanguage, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(DatabaseDisplayName, other.DatabaseDisplayName, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(DatabaseName, other.DatabaseName, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(EnclaveAttestationProtocol, other.EnclaveAttestationProtocol, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(EnclaveAttestationUrl, other.EnclaveAttestationUrl, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(Encrypt, other.Encrypt, System.StringComparison.InvariantCultureIgnoreCase)
+ && ExpiresOn == other.ExpiresOn
+ && string.Equals(FailoverPartner, other.FailoverPartner, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(HostNameInCertificate, other.HostNameInCertificate, System.StringComparison.InvariantCultureIgnoreCase)
+ && LoadBalanceTimeout == other.LoadBalanceTimeout
+ && MaxPoolSize == other.MaxPoolSize
+ && MinPoolSize == other.MinPoolSize
+ && MultipleActiveResultSets == other.MultipleActiveResultSets
+ && MultiSubnetFailover == other.MultiSubnetFailover
+ && PacketSize == other.PacketSize
+ && string.Equals(Password, other.Password, System.StringComparison.InvariantCultureIgnoreCase)
+ && PersistSecurityInfo == other.PersistSecurityInfo
+ && Pooling == other.Pooling
+ && Port == other.Port
+ && Replication == other.Replication
+ && string.Equals(ServerName, other.ServerName, System.StringComparison.InvariantCultureIgnoreCase)
+ && TrustServerCertificate == other.TrustServerCertificate
+ && string.Equals(TypeSystemVersion, other.TypeSystemVersion, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(UserName, other.UserName, System.StringComparison.InvariantCultureIgnoreCase)
+ && string.Equals(WorkstationId, other.WorkstationId, System.StringComparison.InvariantCultureIgnoreCase);
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionDetailsTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionDetailsTests.cs
index 0387d7f81c..900973c787 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionDetailsTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionDetailsTests.cs
@@ -261,5 +261,25 @@ public void SettingConnectiomTimeoutToLongWhichCannotBeConvertedToIntShouldNotCr
Assert.That(details.ConnectTimeout, Is.EqualTo(expectedValue), "Connect Timeout not as expected");
Assert.That(details.Encrypt, Is.EqualTo("Mandatory"), "Encrypt should be mandatory.");
}
+
+ [Test]
+ public void ConnectionSettingsComparableShouldConsiderAdvancedOptions()
+ {
+ ConnectionDetails details1 = new ConnectionDetails()
+ {
+ ServerName = "Server1",
+ DatabaseName = "Database",
+ AuthenticationType = "Integrated",
+ Encrypt = "Mandatory",
+ TrustServerCertificate = true
+ };
+
+ ConnectionDetails details2 = details1.Clone();
+ details2.ConnectTimeout = 60;
+ Assert.That(details1.IsComparableTo(details2), Is.False, "Different Connection Settings must not be comparable.");
+
+ details1 = details2.Clone();
+ Assert.That(details1.IsComparableTo(details2), Is.True, "Same Connection Settings must be comparable.");
+ }
}
}