@@ -34,7 +34,7 @@ public static void ConnectToSQLWithInstanceNameTest()
3434 }
3535 }
3636
37- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
37+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsNotAzureServer ) , nameof ( DataTestUtility . IsNotAzureSynapse ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
3838 [ InlineData ( true , SqlConnectionIPAddressPreference . IPv4First ) ]
3939 [ InlineData ( true , SqlConnectionIPAddressPreference . IPv6First ) ]
4040 [ InlineData ( true , SqlConnectionIPAddressPreference . UsePlatformDefault ) ]
@@ -47,38 +47,25 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
4747 builder . MultiSubnetFailover = useMultiSubnetFailover ;
4848 builder . IPAddressPreference = ipPreference ;
4949
50-
51- Assert . True ( ParseDataSource ( builder . DataSource , out string hostname , out _ , out string instanceName ) ) ;
50+ Assert . True ( ParseDataSource ( builder . DataSource , out string hostname , out _ , out string instanceName ) , "Invalid data source." ) ;
5251
5352 if ( IsBrowserAlive ( hostname ) && IsValidInstance ( hostname , instanceName ) )
5453 {
5554 builder . DataSource = hostname + "\\ " + instanceName ;
56- try
57- {
58- using SqlConnection connection = new ( builder . ConnectionString ) ;
59- connection . Open ( ) ;
60- }
61- catch ( Exception ex )
62- {
63- Assert . True ( false , "Unexpected connection failure: " + ex . Message ) ;
64- }
55+
56+ using SqlConnection connection = new ( builder . ConnectionString ) ;
57+ connection . Open ( ) ;
6558 }
6659
6760 builder . ConnectTimeout = 2 ;
6861 instanceName = "invalidinstance3456" ;
6962 if ( ! IsValidInstance ( hostname , instanceName ) )
7063 {
7164 builder . DataSource = hostname + "\\ " + instanceName ;
72- try
73- {
74- using SqlConnection connection = new ( builder . ConnectionString ) ;
75- connection . Open ( ) ;
76- Assert . True ( false , "Unexpected connection success against " + instanceName ) ;
77- }
78- catch ( Exception ex )
79- {
80- Assert . Contains ( "Error Locating Server/Instance Specified" , ex . Message ) ;
81- }
65+
66+ using SqlConnection connection = new ( builder . ConnectionString ) ;
67+ SqlException ex = Assert . Throws < SqlException > ( ( ) => connection . Open ( ) ) ;
68+ Assert . Contains ( "Error Locating Server/Instance Specified" , ex . Message ) ;
8269 }
8370 }
8471
0 commit comments