¿And if the connection to @dbname comes from a view of another database on the same server?
FOR SELECT spid, dbname FROM #tmpUsers WHERE dbname = @dbname
¡¡appear only direct connections!! :doze:
the connection to the VIEW will return the database to which it belongs , not to the database where are accessing