Where are the connections coming from?

Mr Edge 221 Reputation points
2022-11-03T16:10:48.057+00:00

We have a few applications on different servers. Over time this hasnt been maintained properly so i dont know which server has an app (whether it be a website or an application) that is connecting to a SQL database on a single server with multiple instances.

Is there any easy way to determine what servers are making calls to each SQL instance and if possible maybe something that could determine which application/website called for that SQL data?

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 26,586 Reputation points
    2022-11-03T17:08:42.197+00:00

    Hi @Mr Edge ,

    You can try system stored procedure sp_who2 on the SQL Server.

    • The HostName column will tell what computer/server is connected to the SQL Server.
    • The DBName column will reveal what database they are using.
    • The ProgramName column may tell you more about a connected application.
    1 person found this answer helpful.
    0 comments No comments

  2. Seeya Xi-MSFT 16,661 Reputation points
    2022-11-04T02:17:05.467+00:00

    Hi @Mr Edge ,

    Welcome to Microsoft Q&A!
    Please try to run the following query to get the application name using the program_name column of sys.dm_exec_sessions:

     SELECT      c.session_id, s.program_name, s.login_name, s.status, st.text  
     FROM        sys.dm_exec_connections c  
     INNER JOIN  sys.dm_exec_sessions s ON c.session_id = s.session_id  
     CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS st  
     ORDER BY    c.session_id  
    

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. DMichaud33 1 Reputation point
    2022-11-03T18:00:19.257+00:00

    You may want to do an xevents trace for logins over a period of time to see who or what is logging in. I just googled and found this website with some decent instructions for setting this up:

    https://voiceofthedba.com/2015/12/16/tracking-logins-with-extended-events/

    0 comments No comments

  4. Erland Sommarskog 122.3K Reputation points MVP Volunteer Moderator
    2022-11-03T22:13:02.067+00:00

    Just a word of caution here: both the hostname and the application name can be set in the connection string.

    With most client APIs, the hostname will default to the actual machine name if not set.

    On the other hand, the program name may only be accurate if the application actually sets in the connection string. This is different for different APIs. But with a .NET application, all you may see is .NET SqliClient Provider, or something like that.

    A different approach would be to examine the applications and their connection strings.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.