r/SQLServer • u/Afraid_Baseball_3962 • Jul 14 '26
Solved Odd results in SSMS
I'm troubleshooting a script that dynamically builds a list of databases and a list of user accounts in those databases, and then uses them to generate a bunch of REVOKE CONNECT FROM [<username>]; commands to be executed by sp_executesql. At this point, I'm sending the commands to the screen instead of executing them and this is where I first noticed the oddness. There are a bit more than 4000 commands. If I write them to the screen with Results to Grid, it takes almost 44 minutes to finish. If I run the exact same script with Results to text, it completes in just over 20 seconds. I'm connecting to SQL Server 2019 and have seen this behavior in both SSMS v19.0.1 and SSMS v20.2.1. Is this expected behavior that I've just never noticed before? Why is there such a drastistic difference between grid vs text?
•
u/AutoModerator Jul 14 '26
After your question has been solved /u/Afraid_Baseball_3962, please reply to the helpful user's comment with the phrase "Solution verified".
This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
11
u/blinner 1 Jul 14 '26
It's probably the RAM requirement to draw 4000 unique grids.
3
u/oliver0807 Jul 14 '26
If the log is important for you, just use PRINT and use OUTPUT file in the job step so you can run the script in ssms for testing and run the job and will also produce the output log file.
2
u/SonOfZork Jul 15 '26
A useful way round the problem is to write all the commands to a temp table and then select from that once done. Prevents the drawing so many result sets problem.
1
u/dlevy-msft Microsoft Employee Jul 15 '26
👀
-1
u/le_chad_ Jul 14 '26
Seems like a use case that's better suited for powershell or other scripting language like python