SQL Server Management Studio (SSMS) Has a available databases dropdown ( to select a database to execute the query.).

Available Databases Dropdown in SSMS

This dropdown behaves weird when you change the connection properties.

Observation 1:
Run the below query in the query window
[sql]
SET PARSEONLY ON
[/sql]

Now when you try to expand the dropdown, the drop down does not expand.

Run the below query to turn off PARSEONLY
[sql]
SET PARSEONLY OFF
[/sql]

Observation 2:

Run the below query in the query window
[sql]
SET ROWCOUNT 2
[/sql]

Now if you try to click on the dropdown, you will find only 2 available databases.

Run the below query to reset ROWCOUNT to 0
[sql]
SET ROWCOUNT 0
[/sql]

Why is the dropdown behaving this way?
SSMS is using the same connection used by the query to fetch the Available databases list.
SSMS runs the below command to fetch the results for the Availabale Databases DropDown, using the same connection used by the Query.
[sql]
SELECT dtb.name AS [Name], dtb.state AS [State] FROM master.sys.databases dtb
[/sql]

Also, You would also get wrong results count into the @@ROWCOUNT, when you run the query and accidentally touch the availabale databases dropdown.

Observation 3:
Run the below query
[sql]
SELECT * FROM SYS.OBJECTS
SELECT @@ROWCOUNT as ROWSCOUNT
[/sql]
Make a note of the ROWSCOUNT Result.

Now run the query
[sql]
SELECT * FROM SYS.OBJECTS
[/sql]

Click on the available databases dropdown and run the below query.

[sql]
SELECT @@ROWCOUNT as ROWSCOUNT
[/sql]

You can identify the difference in the values of @@ROWCOUNT.

The first result would be the number of objects in the database.
The second result would be the number of databases in the Server.

One Reply to “SSMS Available Databases DropDown Acts weird if Connection Properties Are Changed”

Leave a Reply to neelu.R Cancel reply

Your email address will not be published. Required fields are marked *