Database Management

AlwaysOn Exception in 2023.3.1 (Error adding to dictionary with key)

After upgrading to 2023.3.1, navigating to the AlwaysOn tab for any target tied to an Availability Group triggers an Exception, and ultimately no AlwaysOn data populates. (Message: Error adding to dictionary with key / Exception: System.ArgumentException: An item with the same key has already been added.) Bug 70459: “Always On dashboard crashes after 2023.3 upgrade”

First published date

7/18/2023 9:47 PM

Last published date

2/6/2026 11:01 PM

Overview

Post 2023.3.1 upgrade, the user navigates to the AlwaysOn tab for any given Target:

image.png

Upon doing so, an Exception is triggered upon doing so, and AlwaysOn data will not populate. The error will also appear in the System Status tab.
Screenshot 2023-07-31 112223.png
Message:
Error adding to dictionary with key: ONE-AG-TARGET.SQLSENTRY.COM

Stack Trace:
An error has occurred:
Message: Error adding to dictionary with key: ONE-AG-TARGET.SQLSENTRY.COM. Caller: clusterNodes. Exception: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Intercerve.SqlSentry.Providers.SqlServer.AlwaysOn.AvailabilityGroupQueryEngine.LoadAllOnConnection[T,TKey](String caller, SqlConnection sqlConnection, String groupQuery, Func`2 keyMapper, Func`2 filterPredicate, IEqualityComparer`1 comparer)

System.InvalidOperationException: Error adding to dictionary with key: ONE-AG-TARGET.SQLSENTRY.COM. Caller: clusterNodes. Exception: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Intercerve.SqlSentry.Providers.SqlServer.AlwaysOn.AvailabilityGroupQueryEngine.LoadAllOnConnection[T,TKey](String caller, SqlConnection sqlConnection, String groupQuery, Func`2 keyMapper, Func`2 filterPredicate, IEqualityComparer`1 comparer) ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Intercerve.SqlSentry.Providers.SqlServer.AlwaysOn.AvailabilityGroupQueryEngine.LoadAllOnConnection[T,TKey](String caller, SqlConnection sqlConnection, String groupQuery, Func`2 keyMapper, Func`2 filterPredicate, IEqualityComparer`1 comparer)
--- End of inner exception stack trace ---
at Intercerve.SqlSentry.Providers.SqlServer.AlwaysOn.AvailabilityGroupQueryEngine.LoadAllOnConnection[T,TKey](String caller, SqlConnection sqlConnection, String groupQuery, Func`2 keyMapper, Func`2 filterPredicate, IEqualityComparer`1 comparer)
at Intercerve.SqlSentry.Providers.SqlServer.AlwaysOn.AvailabilityGroupQueryEngine.UpdateAvailabilityGroupTopology()
at Intercerve.SqlSentry.GUI.Controls.PerformanceAdvisor.AlwaysOn.AlwaysOnInstance.LoadThreadedDataInternal(GenericInfoReloadContext reloadContext)
at Intercerve.SqlSentry.GUI.Controls.GenericInfo.LoadDataLoop(Object state)

Product section

SQL Sentry (SQLS)

Cause

Changes implemented in 2023.3.1 to address bug 70256: “AlwaysOn Tab Blank due to Duplicate Clusters Names in Different Domains,” did not account for some additional cleanup/updates required in the database.

Resolution

The below cleans up orphaned AG-related data still referencing the Simple Name, resolving the Dictionary/Duplicate Key Error, and allowing the AlwaysOn tab to populate.

  1. Close the SQL Sentry Client.
  2. Execute the below query against the SQL Sentry DB.
  3. Re-open the SQL Sentry Client. It may take a few minutes for the errors to go away.

 

-- Scripts are not supported under any SolarWinds support program or service.
-- Scripts are provided AS IS without warranty of any kind. SolarWinds further
-- disclaims all warranties including, without limitation, any implied warranties
-- of merchantability or of fitness for a particular purpose. The risk arising
-- out of the use or performance of the scripts and documentation stays with you.
-- In no event shall SolarWinds or anyone else involved in the creation,
-- production, or delivery of the scripts be liable for any damages whatsoever
-- (including, without limitation, damages for loss of business profits, business
-- interruption, loss of business information, or other pecuniary loss) arising
-- out of the use of or inability to use the scripts or documentation.


DELETE FROM AlwaysOn.ClusterNode
WHERE ClusterID IN (
SELECT c1.ID
FROM AlwaysOn.Cluster c1
JOIN AlwaysOn.Cluster c2 ON c2.Name = c1.Name
WHERE c1.DomainName IS NULL AND c2.DomainName IS NOT NULL);

DELETE FROM c1
FROM AlwaysOn.Cluster c1
JOIN AlwaysOn.Cluster c2 ON c2.Name = c1.Name
WHERE c1.DomainName IS NULL AND c2.DomainName IS NOT NULL;
DELETE FROM cr1
FROM AlwaysOn.ClusterReference cr1
JOIN AlwaysOn.ClusterReference cr2 ON cr2.ClusterName = cr1.ClusterName
AND cr2.EventSourceConnectionID = cr1.EventSourceConnectionID
WHERE cr1.DomainName IS NULL AND cr2.DomainName IS NOT NULL;