@@ -200,11 +200,17 @@ public static void ExceptionTests()
200200 }
201201
202202 // Synapse: 110003;Invalid user or password
203- [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
203+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
204204 public static void VariousExceptionTests ( )
205205 {
206206 SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder ( DataTestUtility . TCPConnectionString ) ;
207-
207+ // Strip the password in connection string if Authentication=Active Directory Managed Identity as it can not be used with a Password
208+ if ( builder . Authentication == SqlAuthenticationMethod . ActiveDirectoryManagedIdentity )
209+ {
210+ string [ ] removeKeys = { "Password" , "PWD" } ;
211+ string connStr = DataTestUtility . RemoveKeysInConnStr ( DataTestUtility . TCPConnectionString , removeKeys ) ;
212+ builder = new SqlConnectionStringBuilder ( connStr ) ;
213+ }
208214
209215 // Test 1 - A
210216 SqlConnectionStringBuilder badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { DataSource = badServer , ConnectTimeout = 1 } ;
@@ -218,11 +224,14 @@ public static void VariousExceptionTests()
218224 }
219225
220226 // Test 1 - B
221- badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { Password = string . Empty , IntegratedSecurity = false , Authentication = SqlAuthenticationMethod . NotSpecified } ;
222- using ( var sqlConnection = new SqlConnection ( badBuilder . ConnectionString ) )
227+ if ( DataTestUtility . IsNotAzureServer ( ) )
223228 {
224- string errorMessage = string . Format ( CultureInfo . InvariantCulture , logonFailedErrorMessage , badBuilder . UserID ) ;
225- VerifyConnectionFailure < SqlException > ( ( ) => sqlConnection . Open ( ) , errorMessage , ( ex ) => VerifyException ( ex , 1 , 18456 , 1 , 14 ) ) ;
229+ badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { Password = string . Empty , IntegratedSecurity = false } ;
230+ using ( var sqlConnection = new SqlConnection ( badBuilder . ConnectionString ) )
231+ {
232+ string errorMessage = string . Format ( CultureInfo . InvariantCulture , logonFailedErrorMessage , badBuilder . UserID ) ;
233+ VerifyConnectionFailure < SqlException > ( ( ) => sqlConnection . Open ( ) , errorMessage , ( ex ) => VerifyException ( ex , 1 , 18456 , 1 , 14 ) ) ;
234+ }
226235 }
227236 }
228237
0 commit comments