2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ #if NETFRAMEWORK
6
+
5
7
using System ;
6
8
using System . Collections . Generic ;
7
9
using System . Data ;
12
14
13
15
namespace Microsoft . Data . Common
14
16
{
17
+ // @TODO: Theoretically this class could be replaced with SqlConnectionString.
18
+
15
19
[ Serializable ] // MDAC 83147
16
- internal sealed class DBConnectionString
20
+ internal sealed class DbConnectionString
17
21
{
18
22
// instances of this class are intended to be immutable, i.e readonly
19
23
// used by permission classes so it is much easier to verify correctness
20
24
// when not worried about the class being modified during execution
21
25
22
- // @TODO: Remove in favor of DbConnectionStringKeywords
23
- private static class KEY
24
- {
25
- internal const string Password = DbConnectionStringKeywords . Password ;
26
- internal const string PersistSecurityInfo = DbConnectionStringKeywords . PersistSecurityInfo ;
27
- internal const string Pwd = DbConnectionStringSynonyms . Pwd ;
28
- } ;
29
-
30
26
// this class is serializable with Everett, so ugly field names can't be changed
31
27
readonly private string _encryptedUsersConnectionString ;
32
28
@@ -51,21 +47,21 @@ private static class KEY
51
47
readonly private string _encryptedActualConnectionString ;
52
48
#pragma warning restore 169
53
49
54
- internal DBConnectionString ( string value , string restrictions , KeyRestrictionBehavior behavior , Dictionary < string , string > synonyms , bool useOdbcRules )
50
+ internal DbConnectionString ( string value , string restrictions , KeyRestrictionBehavior behavior , Dictionary < string , string > synonyms , bool useOdbcRules )
55
51
: this ( new DbConnectionOptions ( value , synonyms ) , restrictions , behavior , synonyms , false )
56
52
{
57
53
// useOdbcRules is only used to parse the connection string, not to parse restrictions because values don't apply there
58
54
// the hashtable doesn't need clone since it isn't shared with anything else
59
55
}
60
56
61
- internal DBConnectionString ( DbConnectionOptions connectionOptions )
57
+ internal DbConnectionString ( DbConnectionOptions connectionOptions )
62
58
: this ( connectionOptions , ( string ) null , KeyRestrictionBehavior . AllowOnly , null , true )
63
59
{
64
- // used by DBDataPermission to convert from DbConnectionOptions to DBConnectionString
60
+ // used by DBDataPermission to convert from DbConnectionOptions to DbConnectionString
65
61
// since backward compatibility requires Everett level classes
66
62
}
67
63
68
- private DBConnectionString ( DbConnectionOptions connectionOptions , string restrictions , KeyRestrictionBehavior behavior , Dictionary < string , string > synonyms , bool mustCloneDictionary )
64
+ private DbConnectionString ( DbConnectionOptions connectionOptions , string restrictions , KeyRestrictionBehavior behavior , Dictionary < string , string > synonyms , bool mustCloneDictionary )
69
65
{ // used by DBDataPermission
70
66
Debug . Assert ( connectionOptions != null , "null connectionOptions" ) ;
71
67
switch ( behavior )
@@ -101,13 +97,13 @@ private DBConnectionString(DbConnectionOptions connectionOptions, string restric
101
97
// serialize out with '*' so already knows what we do. Better this way
102
98
// than to treat password specially later on which causes problems.
103
99
const string star = "*" ;
104
- if ( _parsetable . ContainsKey ( KEY . Password ) )
100
+ if ( _parsetable . ContainsKey ( DbConnectionStringKeywords . Password ) )
105
101
{
106
- _parsetable [ KEY . Password ] = star ;
102
+ _parsetable [ DbConnectionStringKeywords . Password ] = star ;
107
103
}
108
- if ( _parsetable . ContainsKey ( KEY . Pwd ) )
104
+ if ( _parsetable . ContainsKey ( DbConnectionStringSynonyms . Pwd ) )
109
105
{
110
- _parsetable [ KEY . Pwd ] = star ;
106
+ _parsetable [ DbConnectionStringSynonyms . Pwd ] = star ;
111
107
}
112
108
113
109
// replace user's password/pwd value with "*" in the linked list and build a new string
@@ -121,7 +117,7 @@ private DBConnectionString(DbConnectionOptions connectionOptions, string restric
121
117
}
122
118
}
123
119
124
- private DBConnectionString ( DBConnectionString connectionString , string [ ] restrictionValues , KeyRestrictionBehavior behavior )
120
+ private DbConnectionString ( DbConnectionString connectionString , string [ ] restrictionValues , KeyRestrictionBehavior behavior )
125
121
{
126
122
// used by intersect for two equal connection strings with different restrictions
127
123
_encryptedUsersConnectionString = connectionString . _encryptedUsersConnectionString ;
@@ -198,7 +194,7 @@ internal bool ContainsKey(string keyword)
198
194
return _parsetable . ContainsKey ( keyword ) ;
199
195
}
200
196
201
- internal DBConnectionString Intersect ( DBConnectionString entry )
197
+ internal DbConnectionString Intersect ( DbConnectionString entry )
202
198
{
203
199
KeyRestrictionBehavior behavior = _behavior ;
204
200
string [ ] restrictionValues = null ;
@@ -287,18 +283,18 @@ internal DBConnectionString Intersect(DBConnectionString entry)
287
283
}
288
284
289
285
// verify _hasPassword & _parsetable are in sync between Everett/Whidbey
290
- Debug . Assert ( ! _hasPassword || ContainsKey ( KEY . Password ) || ContainsKey ( KEY . Pwd ) , "OnDeserialized password mismatch this" ) ;
291
- Debug . Assert ( entry == null || ! entry . _hasPassword || entry . ContainsKey ( KEY . Password ) || entry . ContainsKey ( KEY . Pwd ) , "OnDeserialized password mismatch entry" ) ;
286
+ Debug . Assert ( ! _hasPassword || ContainsKey ( DbConnectionStringKeywords . Password ) || ContainsKey ( DbConnectionStringSynonyms . Pwd ) , "OnDeserialized password mismatch this" ) ;
287
+ Debug . Assert ( entry == null || ! entry . _hasPassword || entry . ContainsKey ( DbConnectionStringKeywords . Password ) || entry . ContainsKey ( DbConnectionStringSynonyms . Pwd ) , "OnDeserialized password mismatch entry" ) ;
292
288
293
- DBConnectionString value = new DBConnectionString ( this , restrictionValues , behavior ) ;
289
+ DbConnectionString value = new DbConnectionString ( this , restrictionValues , behavior ) ;
294
290
ValidateCombinedSet ( this , value ) ;
295
291
ValidateCombinedSet ( entry , value ) ;
296
292
297
293
return value ;
298
294
}
299
295
300
296
[ Conditional ( "DEBUG" ) ]
301
- private void ValidateCombinedSet ( DBConnectionString componentSet , DBConnectionString combinedSet )
297
+ private void ValidateCombinedSet ( DbConnectionString componentSet , DbConnectionString combinedSet )
302
298
{
303
299
Debug . Assert ( combinedSet != null , "The combined connection string should not be null" ) ;
304
300
if ( ( componentSet != null ) && ( combinedSet . _restrictionValues != null ) && ( componentSet . _restrictionValues != null ) )
@@ -371,10 +367,10 @@ private bool IsRestrictedKeyword(string key)
371
367
return ( _restrictionValues == null || ( 0 > Array . BinarySearch ( _restrictionValues , key , StringComparer . Ordinal ) ) ) ;
372
368
}
373
369
374
- internal bool IsSupersetOf ( DBConnectionString entry )
370
+ internal bool IsSupersetOf ( DbConnectionString entry )
375
371
{
376
- Debug . Assert ( ! _hasPassword || ContainsKey ( KEY . Password ) || ContainsKey ( KEY . Pwd ) , "OnDeserialized password mismatch this" ) ;
377
- Debug . Assert ( ! entry . _hasPassword || entry . ContainsKey ( KEY . Password ) || entry . ContainsKey ( KEY . Pwd ) , "OnDeserialized password mismatch entry" ) ;
372
+ Debug . Assert ( ! _hasPassword || ContainsKey ( DbConnectionStringKeywords . Password ) || ContainsKey ( DbConnectionStringSynonyms . Pwd ) , "OnDeserialized password mismatch this" ) ;
373
+ Debug . Assert ( ! entry . _hasPassword || entry . ContainsKey ( DbConnectionStringKeywords . Password ) || entry . ContainsKey ( DbConnectionStringSynonyms . Pwd ) , "OnDeserialized password mismatch entry" ) ;
378
374
379
375
switch ( _behavior )
380
376
{
@@ -481,10 +477,10 @@ static private string[] NoDuplicateUnion(string[] a, string[] b)
481
477
return restrictionValues ;
482
478
}
483
479
484
- private static string [ ] ParseRestrictions ( string restrictions , Dictionary < string , string > synonyms )
480
+ private static string [ ] ParseRestrictions ( string restrictions , IReadOnlyDictionary < string , string > synonyms )
485
481
{
486
482
#if DEBUG
487
- SqlClientEventSource . Log . TryAdvancedTraceEvent ( "<comm.DBConnectionString |INFO|ADV> Restrictions='{0}'" , restrictions ) ;
483
+ SqlClientEventSource . Log . TryAdvancedTraceEvent ( "<comm.DbConnectionString |INFO|ADV> Restrictions='{0}'" , restrictions ) ;
488
484
#endif
489
485
List < string > restrictionValues = new List < string > ( ) ;
490
486
StringBuilder buffer = new StringBuilder ( restrictions . Length ) ;
@@ -500,7 +496,7 @@ private static string[] ParseRestrictions(string restrictions, Dictionary<string
500
496
if ( ! string . IsNullOrEmpty ( keyname ) )
501
497
{
502
498
#if DEBUG
503
- SqlClientEventSource . Log . TryAdvancedTraceEvent ( "<comm.DBConnectionString |INFO|ADV> KeyName='{0}'" , keyname ) ;
499
+ SqlClientEventSource . Log . TryAdvancedTraceEvent ( "<comm.DbConnectionString |INFO|ADV> KeyName='{0}'" , keyname ) ;
504
500
#endif
505
501
string realkeyname = synonyms != null ? ( string ) synonyms [ keyname ] : keyname ; // MDAC 85144
506
502
if ( string . IsNullOrEmpty ( realkeyname ) )
@@ -568,3 +564,5 @@ private static void Verify(string[] restrictionValues)
568
564
}
569
565
}
570
566
}
567
+
568
+ #endif
0 commit comments