Nigel Tunnicliffe
Nigel Tunnicliffe

Reputation: 131

Logging the Connection String used to access SQL database

Is there any way of logging the connection string used to access a SQL database?. We have a C# application which has many places where the application opens a connection to SQL, performs a query and then closes the connection. At some point it is using the wrong connection string without the port number to connect to the appropriate SQL instance but seems to continue to work but responses are very slow.

I have several links to audit which users are logged on etc but none of them record the connection string used. Is there something like an inbuilt SQL query I can use to find this information?

Thanks

Upvotes: 1

Views: 922

Answers (1)

aork 123
aork 123

Reputation: 21

If you want to log the answer within your application then sql won't be able to help you here, I would suggest you create a wrapper method around your sql call. the exact code will vary according to the library you use but in c# esc pseudocode it would look something like

private string RunSql(parameters)
{
    myLogger.log($"my connection string is {connectionString}");
    connection.Execute(parameters);
}

Upvotes: 2

Related Questions