This is a re-post of an article by Michael Garrison that appeared on the old Shoulder The Boulder site. I'm reposting it here to keep the useful information alive.

Version 7 has mostly eliminated our ability to get ourselves in trouble with this, but it still comes up from time to time.

If you find that pages timeout when loading group viewer pages, or you get cryptic error messages referencing MultipleActiveResultSets=true, you may have groups which are of a type that inherit from another group type, which in turn inherits from the first group type. That's an infinite loop, and it does bad things in programming.

There's no automatic fix for this, as you just need to fix the group type definitions and the group types they inherit from. But the trick is to find which groups and grouptypes are causing the issues.

To accomplish this, there are two different SQL queries you can run in Admin Tools -> Power Tools -> SQL Command

WITH FindRoot AS
(
    SELECT [Id],[InheritedGroupTypeId], CAST([Id] AS NVARCHAR(MAX)) Path
    FROM [GroupType]
    UNION ALL
    SELECT C.[Id], P.[InheritedGroupTypeId], C.Path + N' > ' + CAST(P.[Id] AS NVARCHAR(MAX))
    FROM [GroupType] P
    JOIN FindRoot C
    ON C.[InheritedGroupTypeId] = P.[Id] AND P.[InheritedGroupTypeId] <> P.[Id] AND C.[InheritedGroupTypeId] <> C.Id
 )
SELECT *
FROM FindRoot R
WHERE R.Id = R.[InheritedGroupTypeId] 
  AND R.[InheritedGroupTypeId] <> 0;

This finds the most common issues, Inherited Types referencing each other. Copy and paste this query into the SQL Command box and click "Run". A properly setup database should find no results. If it does find one or more results, it's going to take another SQL query to fix the issue (trying to load the Group Type page to fix it will also timeout until this is fixed). Take a look at the first item returned and note the Id.

The new SQL to run is:

UPDATE [GroupType] SET [InheritedGroupTypeId] = NULL WHERE [Id] = ##FirstIdReturned##

Put the ID you got back at the end in place of "##FirstIdReturned##", and flip the Selection Query? setting to "No" before running this second query. It should tell you that one row was updated - now you can go and see if the issue is fixed.

If you're uncomfortable AT ALL with making these changes in SQL, join us in Chat and let us know in the #troubleshooting channel what results you're getting.

If that doesn't solve your issue, use this query in the same way to look for Group Type Association issues instead:

WITH TreeCrawler as
(
    SELECT gta.GroupTypeId, gta.ChildGroupTypeId, 1 AS Depth
    FROM [GroupTypeAssociation] gta
	UNION ALL
	SELECT gta2.GroupTypeId, gta2.ChildGroupTypeId, tc.Depth + 1
    FROM
        [GroupTypeAssociation] gta2
	    INNER JOIN TreeCrawler tc ON tc.GroupTypeId = gta2.ChildGroupTypeId
	WHERE tc.Depth < 20 AND gta2.GroupTypeId != gta2.ChildGroupTypeId
)
SELECT GroupTypeId, ChildGroupTypeId FROM TreeCrawler tc
WHERE Depth > 19
GROUP BY GroupTypeId, ChildGroupTypeId

If you find results from these queries but can't figure out how to solve them, jump into Chat and let us know in the #troubleshooting channel what these queries found, and we'll help you get it put to rights.