OK, so you retain a current db selection against each socket id. I can see this getting tricky, since a new socket is generated if a user refreshes the page for example (I think). Have you mocked up and tested this side of things to make sure your underlying concept will work ok?
On the actual question you have asked I can't see an immediate solution, but that does not mean that there is not one.
I maintain the socket ID on message (actually Dashboard does this automatically).
User selected the name of the DB and clicked ok button. This generates a message wiith both db name and that user socket ID.
So when the DB query returns something i maintain the socket ID and results are sent back to the user on the Dashboard.
If user disconnects/refreshes - then the story ends there for that socket ID. Worst case scenario - i have a message in transit (user selected DB name & clicked ok and then he refreshed before getting results ) - this message would go to DB get data - and be unable to display to relevant user since that socket id is lost. This is ok for my use case. (In case of user disconnects/refreshes - i am catching the lost event and sending the user back to start of process. )
Lets see if someone else has else it would be switch .