@@ -89,6 +89,7 @@ private static readonly Dictionary<string, SqlColumnEncryptionKeyStoreProvider>
8989 private IReadOnlyDictionary < string , SqlColumnEncryptionKeyStoreProvider > _customColumnEncryptionKeyStoreProviders ;
9090
9191 private Func < SqlAuthenticationParameters , CancellationToken , Task < SqlAuthenticationToken > > _accessTokenCallback ;
92+ private Func < SSPIContextProvider > _sspiContextProviderFactory ;
9293
9394 internal bool HasColumnEncryptionKeyStoreProvidersRegistered =>
9495 _customColumnEncryptionKeyStoreProviders is not null && _customColumnEncryptionKeyStoreProviders . Count > 0 ;
@@ -648,7 +649,7 @@ public override string ConnectionString
648649 CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessTokenCallback ( connectionOptions ) ;
649650 }
650651 }
651- ConnectionString_Set ( new SqlConnectionPoolKey ( value , _credential , _accessToken , _accessTokenCallback ) ) ;
652+ ConnectionString_Set ( new SqlConnectionPoolKey ( value , _credential , _accessToken , _accessTokenCallback , _sspiContextProviderFactory ) ) ;
652653 _connectionString = value ; // Change _connectionString value only after value is validated
653654 CacheConnectionStringProperties ( ) ;
654655 }
@@ -708,7 +709,7 @@ public string AccessToken
708709 }
709710
710711 // Need to call ConnectionString_Set to do proper pool group check
711- ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , credential : _credential , accessToken : value , accessTokenCallback : null ) ) ;
712+ ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , credential : _credential , accessToken : value , accessTokenCallback : null , sspiContextProviderFactory : _sspiContextProviderFactory ) ) ;
712713 _accessToken = value ;
713714 }
714715 }
@@ -731,11 +732,22 @@ public Func<SqlAuthenticationParameters, CancellationToken, Task<SqlAuthenticati
731732 CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessTokenCallback ( ( SqlConnectionString ) ConnectionOptions ) ;
732733 }
733734
734- ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , credential : _credential , accessToken : null , accessTokenCallback : value ) ) ;
735+ ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , credential : _credential , accessToken : null , accessTokenCallback : value , sspiContextProviderFactory : _sspiContextProviderFactory ) ) ;
735736 _accessTokenCallback = value ;
736737 }
737738 }
738739
740+ /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/SSPIContextProviderFactory/*' />
741+ public Func < SSPIContextProvider > SSPIContextProviderFactory
742+ {
743+ get { return _sspiContextProviderFactory ; }
744+ set
745+ {
746+ ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , credential : _credential , accessToken : null , accessTokenCallback : _accessTokenCallback , sspiContextProviderFactory : value ) ) ;
747+ _sspiContextProviderFactory = value ;
748+ }
749+ }
750+
739751 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/Database/*' />
740752 [ ResDescription ( StringsHelper . ResourceNames . SqlConnection_Database ) ]
741753 [ ResCategory ( StringsHelper . ResourceNames . SqlConnection_DataSource ) ]
@@ -1030,7 +1042,7 @@ public SqlCredential Credential
10301042 _credential = value ;
10311043
10321044 // Need to call ConnectionString_Set to do proper pool group check
1033- ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , _credential , accessToken : _accessToken , accessTokenCallback : _accessTokenCallback ) ) ;
1045+ ConnectionString_Set ( new SqlConnectionPoolKey ( _connectionString , _credential , accessToken : _accessToken , accessTokenCallback : _accessTokenCallback , _sspiContextProviderFactory ) ) ;
10341046 }
10351047 }
10361048
@@ -1078,7 +1090,7 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessToken(S
10781090 throw ADP . InvalidMixedUsageOfCredentialAndAccessToken ( ) ;
10791091 }
10801092
1081- if ( _accessTokenCallback != null )
1093+ if ( _accessTokenCallback != null )
10821094 {
10831095 throw ADP . InvalidMixedUsageOfAccessTokenAndTokenCallback ( ) ;
10841096 }
@@ -1100,7 +1112,7 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessTokenCa
11001112 throw ADP . InvalidMixedUsageOfAccessTokenCallbackAndAuthentication ( ) ;
11011113 }
11021114
1103- if ( _accessToken != null )
1115+ if ( _accessToken != null )
11041116 {
11051117 throw ADP . InvalidMixedUsageOfAccessTokenAndTokenCallback ( ) ;
11061118 }
@@ -2214,7 +2226,7 @@ public static void ChangePassword(string connectionString, string newPassword)
22142226 throw ADP . InvalidArgumentLength ( nameof ( newPassword ) , TdsEnums . MAXLEN_NEWPASSWORD ) ;
22152227 }
22162228
2217- SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential : null , accessToken : null , accessTokenCallback : null ) ;
2229+ SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential : null , accessToken : null , accessTokenCallback : null , sspiContextProviderFactory : null ) ;
22182230
22192231 SqlConnectionString connectionOptions = SqlConnectionFactory . FindSqlConnectionOptions ( key ) ;
22202232 if ( connectionOptions . IntegratedSecurity )
@@ -2263,7 +2275,7 @@ public static void ChangePassword(string connectionString, SqlCredential credent
22632275 throw ADP . InvalidArgumentLength ( nameof ( newSecurePassword ) , TdsEnums . MAXLEN_NEWPASSWORD ) ;
22642276 }
22652277
2266- SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential , accessToken : null , accessTokenCallback : null ) ;
2278+ SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential , accessToken : null , accessTokenCallback : null , sspiContextProviderFactory : null ) ;
22672279
22682280 SqlConnectionString connectionOptions = SqlConnectionFactory . FindSqlConnectionOptions ( key ) ;
22692281
@@ -2302,7 +2314,7 @@ private static void ChangePassword(string connectionString, SqlConnectionString
23022314 if ( con != null )
23032315 con . Dispose ( ) ;
23042316 }
2305- SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential , accessToken : null , accessTokenCallback : null ) ;
2317+ SqlConnectionPoolKey key = new SqlConnectionPoolKey ( connectionString , credential , accessToken : null , accessTokenCallback : null , sspiContextProviderFactory : null ) ;
23062318
23072319 SqlConnectionFactory . SingletonInstance . ClearPool ( key ) ;
23082320 }
0 commit comments