@@ -201,11 +201,17 @@ public static void ExceptionTests()
201
201
}
202
202
203
203
// Synapse: 110003;Invalid user or password
204
- [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
204
+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
205
205
public static void VariousExceptionTests ( )
206
206
{
207
207
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder ( DataTestUtility . TCPConnectionString ) ;
208
-
208
+ // Strip the password in connection string if Authentication=Active Directory Managed Identity as it can not be used with a Password
209
+ if ( builder . Authentication == SqlAuthenticationMethod . ActiveDirectoryManagedIdentity )
210
+ {
211
+ string [ ] removeKeys = { "Password" , "PWD" } ;
212
+ string connStr = DataTestUtility . RemoveKeysInConnStr ( DataTestUtility . TCPConnectionString , removeKeys ) ;
213
+ builder = new SqlConnectionStringBuilder ( connStr ) ;
214
+ }
209
215
210
216
// Test 1 - A
211
217
SqlConnectionStringBuilder badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { DataSource = badServer , ConnectTimeout = 1 } ;
@@ -219,11 +225,14 @@ public static void VariousExceptionTests()
219
225
}
220
226
221
227
// Test 1 - B
222
- badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { Password = string . Empty , IntegratedSecurity = false , Authentication = SqlAuthenticationMethod . NotSpecified } ;
223
- using ( var sqlConnection = new SqlConnection ( badBuilder . ConnectionString ) )
228
+ if ( DataTestUtility . IsNotAzureServer ( ) )
224
229
{
225
- string errorMessage = string . Format ( CultureInfo . InvariantCulture , logonFailedErrorMessage , badBuilder . UserID ) ;
226
- VerifyConnectionFailure < SqlException > ( ( ) => sqlConnection . Open ( ) , errorMessage , ( ex ) => VerifyException ( ex , 1 , 18456 , 1 , 14 ) ) ;
230
+ badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { Password = string . Empty , IntegratedSecurity = false } ;
231
+ using ( var sqlConnection = new SqlConnection ( badBuilder . ConnectionString ) )
232
+ {
233
+ string errorMessage = string . Format ( CultureInfo . InvariantCulture , logonFailedErrorMessage , badBuilder . UserID ) ;
234
+ VerifyConnectionFailure < SqlException > ( ( ) => sqlConnection . Open ( ) , errorMessage , ( ex ) => VerifyException ( ex , 1 , 18456 , 1 , 14 ) ) ;
235
+ }
227
236
}
228
237
}
229
238
0 commit comments