You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The connection pool doesn't work well with explicit access tokens because SqlConnectionPoolKey uses reference equality to compare access tokens. It should use string.Equals instead.
Create two strings at1 and at2 which contain the same valid access token.
Open a connection with pooling enabled (which is the default); set SqlConnection.AccessToken to at1 and run a query. Close the connection. Open a second connection with pooling enabled; set SqlConnection.AccessToken to at2 and run a second query. Check the number of open connections on the server; it will be 2.
Repeat the experiment except using at1 both times. There will only be a single open connection on the server.
Expected behavior
Pooled connections using an explicit access token should be shared even if different string objects containing the same value were used to initialize the connection.
Further technical details
N/A
The text was updated successfully, but these errors were encountered:
I'm using a simple test to verify this behavior with Microsoft.Data.SqlClient (targeting .NET Framework) but I don't see multiple connections getting created, please find my repro app attached below, and let me know if I understood the use-case same way.
I created 6 connections with different objects for access tokens, some global, and some local scope, but below was my result:
App is kept running to keep pooled connection active.
On querying database with sp_who2, I see my application has only 1 active connection.
On querying database with the SPID of the active connection, with query: select num_reads from sys.dm_exec_connections where session_id = @@SPID,
I get output: 6.
Please help me reproduce the problem. Thanks! TestAAD.zip
Describe the bug
The connection pool doesn't work well with explicit access tokens because SqlConnectionPoolKey uses reference equality to compare access tokens. It should use string.Equals instead.
The error is in line
SqlClient/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs
Line 113 in 654933a
To reproduce
Create two strings at1 and at2 which contain the same valid access token.
Open a connection with pooling enabled (which is the default); set SqlConnection.AccessToken to at1 and run a query. Close the connection. Open a second connection with pooling enabled; set SqlConnection.AccessToken to at2 and run a second query. Check the number of open connections on the server; it will be 2.
Repeat the experiment except using at1 both times. There will only be a single open connection on the server.
Expected behavior
Pooled connections using an explicit access token should be shared even if different string objects containing the same value were used to initialize the connection.
Further technical details
N/A
The text was updated successfully, but these errors were encountered: