0

I know there was a similar question before at SO as shown here However, that answer really does not address my question. So here is my scenario, and I will demo it with PowerShell.

The following code will create two sessions on my local sql2016 instance

#The only difference in the two connection strings is [pooling] property, the $connstr_1 has pooling=true, while the $connstr_2 has pooling=false.

$connstr_1 = "data source=localhost\sql2016; initial catalog=master; trusted_connection=true; app=ConnPoolTest; pooling=true";
$SqlConnection1 = New-Object System.Data.SqlClient.SqlConnection($connstr_1)


$connstr_2 = "data source=localhost\sql2016; initial catalog=master; trusted_connection=true; app=ConnPoolTest; pooling=false";
$SqlConnection2 = New-Object System.Data.SqlClient.SqlConnection($connstr_2)

$SqlConnection1.Open()

$SqlConnection2.Open();

My question is on sql server side, how can I know which session's connection string has pooling property set to true and which set to false?

5

My question is on sql server side, how can I know which session's connection string has pooling property set to true and which set to false?

You generally won't and can't. The connection string isn't sent to SQL Server, it's a directive for the driver on what information and options it needs in order connect and how it should act in certain situations. The connections string itself, however, is not sent to SQL Server and it's generally not possible to reconstruct it in its entirety just form the information surfaced by SQL Server.

In your example, the pooling options tells the driver whether or not to use connection pooling. SQL Server doesn't care about this, nor does it know about this as it's entirely a driver/application construct.

  • Same with initial database. The connection can switch databsaes (use command) - that doesn ot change the initial db choice, which can be in the connection string. – TomTom Oct 13 '18 at 13:10
  • @TomTom Correct! It's also possible to spoof data and there is no way for SQL Server to know so it blindly accepts the values. This is why we should go back to the application owner/designer and get the information from the source. – Sean Gallardy Oct 13 '18 at 13:29
  • Thanks Sean. I totally agree as I have been suspicious about this "server side knows connection string" idea for long time. – jyao Oct 13 '18 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.