As a DBA, its our job to keep an eye on the database to make sure it’s performing well and in safe hands, so we often query into our database to see who are currently logged-in and what have been they executing on the database etc etc? Every DBA does that and they do have some own handwritten query to find out the user and session information. Likewise I have one too, which gives me the hostname, program name, login name, status, total elapsed time and the query. This is how, I usually visit my SQL Server to find out the session statistics.
Now you must be wondering, is there a way to hide hostname and program name from where a connection is being made to SQL Server via SSMS? Yes, there is a way!!
Step 01: Open SSMS → “New Connection” → “Options >>”
Step 02: “Additional Connection Parameters” → In the text area put below string
Workstation ID=”PRASAD-SAHOO”;Application Name=”WWW.SQLINDIA.COM”
Step 03: We have overridden the connection information, now log-in and verify the same by executing below queries.
SELECT HOST_NAME() as HostName, APP_NAME() as ProgramName EXEC sp_who2 active select * from (select a.session_id, a.host_name, a.program_name, a.login_name, a.status, a.total_elapsed_time, OBJECT_NAME(c.objectid) as obj, c.text FROM sys.dm_exec_sessions a inner JOIN sys.dm_exec_connections b ON a.session_id = b.session_id CROSS APPLY sys.dm_exec_sql_text(b.most_recent_sql_handle) c) t WHERE t.session_id = @@spid