@@ -34,7 +34,7 @@ public static void ConnectToSQLWithInstanceNameTest()
34
34
}
35
35
}
36
36
37
- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
37
+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsNotAzureServer ) , nameof ( DataTestUtility . IsNotAzureSynapse ) , nameof ( DataTestUtility . AreConnStringsSetup ) ) ]
38
38
[ InlineData ( true , SqlConnectionIPAddressPreference . IPv4First ) ]
39
39
[ InlineData ( true , SqlConnectionIPAddressPreference . IPv6First ) ]
40
40
[ InlineData ( true , SqlConnectionIPAddressPreference . UsePlatformDefault ) ]
@@ -47,38 +47,25 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
47
47
builder . MultiSubnetFailover = useMultiSubnetFailover ;
48
48
builder . IPAddressPreference = ipPreference ;
49
49
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." ) ;
52
51
53
52
if ( IsBrowserAlive ( hostname ) && IsValidInstance ( hostname , instanceName ) )
54
53
{
55
54
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 ( ) ;
65
58
}
66
59
67
60
builder . ConnectTimeout = 2 ;
68
61
instanceName = "invalidinstance3456" ;
69
62
if ( ! IsValidInstance ( hostname , instanceName ) )
70
63
{
71
64
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 ) ;
82
69
}
83
70
}
84
71
0 commit comments