@@ -201,11 +201,17 @@ public static void ExceptionTests()
201201 }
202202
203203 // 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 ) ) ]
205205 public static void VariousExceptionTests ( )
206206 {
207207 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+ }
209215
210216 // Test 1 - A
211217 SqlConnectionStringBuilder badBuilder = new SqlConnectionStringBuilder ( builder . ConnectionString ) { DataSource = badServer , ConnectTimeout = 1 } ;
@@ -219,11 +225,14 @@ public static void VariousExceptionTests()
219225 }
220226
221227 // 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 ( ) )
224229 {
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+ }
227236 }
228237 }
229238
0 commit comments