SQL connection strings

CycleDude 61 Reputation points
2022-01-06T18:38:51.173+00:00

I have a few SQL Servers, and I need to figure out a way to query all of them and extract the connection strings to determine which other servers are making connections to the SQL servers. Is there a way to do this task? Thanks all.

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

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-01-06T19:52:03.317+00:00

    If I am reading your question correctly, you want to query each server to get the connection string for how to connect to that server.

    That is not information you find in the server itself, but it is up to the caller how to refer to the server in the connection string. And there are some options:

    1. By server name only.
    2. By FQDN.
    3. By IP-address.
    4. By a DNS-alias. That is, while the name of the server is Charles, there is an alias somewhere mapping James to Charles, so that James works as well.
    5. The same above, except that the alias is set up in /etc/hosts locally on the server, or in the registry (through SQL Server Configuration Manager, for instance.)

    And if server in question is a named instance, the instance may be referred to by name or port number. Or by an alias.

    A better approach may be to set up logon triggers that logs the information from the eventdata() function in a table. Of particular interest is the client_net_address attribute, which informs you from which machine the connection was made.

    But be careful! Incorrectly implemented logon trigger can cause an outage when no one can login.

    0 comments No comments

  2. YufeiShao-msft 7,146 Reputation points
    2022-01-07T05:50:23.59+00:00

    Hi @CycleDude

    If you want to determine what apps are accessing SQL Server, the first place to start is SQL server profiler(Trace). This tool will allow you to track all the app and users that login to the server and access SQL for as long as the trace is running. Choose the correct events to capture, such as Audit Login. Use activity monitor for the same.

    If you want to know connection string, the easiest way to get is using the "Server Explorer" in Visual Studio if you have,
    Get the details from this thread: How to get the connection String from a database

    -------------

    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.

    0 comments No comments

  3. Olaf Helper 47,436 Reputation points
    2022-01-07T06:33:50.743+00:00

    extract the connection strings

    Extract from where? There is no repository storing such informations.
    A connction string is a client setting and highly depends on the used data provider like ODBC, OleDB, ADO.NET etc.

    See https://www.connectionstrings.com/sql-server/

    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.