Merge pull request #3389 from lambdageek/bug-43099
[mono.git] / mcs / class / referencesource / System.Data / System / Data / SqlClient / SqlConnectionStringBuilder.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SqlConnectionStringBuilder.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">[....]</owner>
6 // <owner current="true" primary="false">[....]</owner>
7 //------------------------------------------------------------------------------
8
9     using System;
10     using System.Collections;
11     using System.Collections.Generic;
12     using System.ComponentModel;
13     using System.Data;
14     using System.Data.Common;
15     using System.Diagnostics;
16     using System.Globalization;
17     using System.Runtime.Serialization;
18     using System.Security.Permissions;
19     using System.Text;
20     using System.Diagnostics.CodeAnalysis;
21
22 namespace System.Data.SqlClient {
23
24     [DefaultProperty("DataSource")]
25     [System.ComponentModel.TypeConverterAttribute(typeof(SqlConnectionStringBuilder.SqlConnectionStringBuilderConverter))]
26     public sealed class SqlConnectionStringBuilder : DbConnectionStringBuilder {
27
28         private enum Keywords { // specific ordering for ConnectionString output construction
29 //            NamedConnection,
30
31             DataSource,
32             FailoverPartner,
33             AttachDBFilename,
34             InitialCatalog,
35             IntegratedSecurity,
36             PersistSecurityInfo,
37             UserID,
38             Password,
39
40             Enlist,
41             Pooling,
42             MinPoolSize,
43             MaxPoolSize,
44             PoolBlockingPeriod,
45
46             AsynchronousProcessing,
47             ConnectionReset,
48             MultipleActiveResultSets,
49             Replication,
50
51             ConnectTimeout,
52             Encrypt,
53             TrustServerCertificate,
54             LoadBalanceTimeout,
55             NetworkLibrary,
56             PacketSize,
57             TypeSystemVersion,
58
59             Authentication,
60
61             ApplicationName,
62             CurrentLanguage,
63             WorkstationID,
64
65             UserInstance,
66
67             ContextConnection,
68
69             TransactionBinding,
70
71             ApplicationIntent,
72
73             MultiSubnetFailover,
74
75             TransparentNetworkIPResolution,
76
77             ConnectRetryCount,
78
79             ConnectRetryInterval,
80
81             ColumnEncryptionSetting,
82
83             // keep the count value last
84             KeywordsCount
85         }
86
87         internal const int KeywordsCount = (int)Keywords.KeywordsCount;
88
89         private static readonly string[] _validKeywords;
90         private static readonly Dictionary<string,Keywords> _keywords;
91
92         private ApplicationIntent _applicationIntent = DbConnectionStringDefaults.ApplicationIntent;
93         private string _applicationName   = DbConnectionStringDefaults.ApplicationName;
94         private string _attachDBFilename  = DbConnectionStringDefaults.AttachDBFilename;
95         private string _currentLanguage   = DbConnectionStringDefaults.CurrentLanguage;
96         private string _dataSource        = DbConnectionStringDefaults.DataSource;
97         private string _failoverPartner   = DbConnectionStringDefaults.FailoverPartner;
98         private string _initialCatalog    = DbConnectionStringDefaults.InitialCatalog;
99 //      private string _namedConnection   = DbConnectionStringDefaults.NamedConnection;
100         private string _networkLibrary    = DbConnectionStringDefaults.NetworkLibrary;
101         private string _password          = DbConnectionStringDefaults.Password;
102         private string _transactionBinding = DbConnectionStringDefaults.TransactionBinding;
103         private string _typeSystemVersion = DbConnectionStringDefaults.TypeSystemVersion;
104         private string _userID            = DbConnectionStringDefaults.UserID;
105         private string _workstationID     = DbConnectionStringDefaults.WorkstationID;
106
107         private int _connectTimeout      = DbConnectionStringDefaults.ConnectTimeout;
108         private int _loadBalanceTimeout  = DbConnectionStringDefaults.LoadBalanceTimeout;
109         private int _maxPoolSize         = DbConnectionStringDefaults.MaxPoolSize;
110         private int _minPoolSize         = DbConnectionStringDefaults.MinPoolSize;
111         private int _packetSize          = DbConnectionStringDefaults.PacketSize;
112         private int _connectRetryCount   = DbConnectionStringDefaults.ConnectRetryCount;
113         private int _connectRetryInterval = DbConnectionStringDefaults.ConnectRetryInterval;
114
115         private bool _asynchronousProcessing            = DbConnectionStringDefaults.AsynchronousProcessing;
116         private bool _connectionReset                           = DbConnectionStringDefaults.ConnectionReset;
117         private bool _contextConnection                         = DbConnectionStringDefaults.ContextConnection;
118         private bool _encrypt                                           = DbConnectionStringDefaults.Encrypt;
119         private bool _trustServerCertificate            = DbConnectionStringDefaults.TrustServerCertificate;
120         private bool _enlist                                            = DbConnectionStringDefaults.Enlist;
121         private bool _integratedSecurity                        = DbConnectionStringDefaults.IntegratedSecurity;
122         private bool _multipleActiveResultSets          = DbConnectionStringDefaults.MultipleActiveResultSets;
123         private bool _multiSubnetFailover                       = DbConnectionStringDefaults.MultiSubnetFailover;
124         private bool _transparentNetworkIPResolution= DbConnectionStringDefaults.TransparentNetworkIPResolution;
125         private bool _persistSecurityInfo                       = DbConnectionStringDefaults.PersistSecurityInfo;
126         private bool _pooling                                           = DbConnectionStringDefaults.Pooling;
127         private bool _replication                                       = DbConnectionStringDefaults.Replication;
128         private bool _userInstance                                      = DbConnectionStringDefaults.UserInstance;
129         private SqlAuthenticationMethod _authentication     = DbConnectionStringDefaults.Authentication;
130         private SqlConnectionColumnEncryptionSetting _columnEncryptionSetting = DbConnectionStringDefaults.ColumnEncryptionSetting;
131         private PoolBlockingPeriod _poolBlockingPeriod = DbConnectionStringDefaults.PoolBlockingPeriod;
132
133         static SqlConnectionStringBuilder() {
134             string[] validKeywords = new string[KeywordsCount];
135             validKeywords[(int)Keywords.ApplicationIntent]              = DbConnectionStringKeywords.ApplicationIntent;
136             validKeywords[(int)Keywords.ApplicationName]                = DbConnectionStringKeywords.ApplicationName;
137             validKeywords[(int)Keywords.AsynchronousProcessing]         = DbConnectionStringKeywords.AsynchronousProcessing;
138             validKeywords[(int)Keywords.AttachDBFilename]               = DbConnectionStringKeywords.AttachDBFilename;
139             validKeywords[(int)Keywords.PoolBlockingPeriod]       = DbConnectionStringKeywords.PoolBlockingPeriod;
140             validKeywords[(int)Keywords.ConnectionReset]                = DbConnectionStringKeywords.ConnectionReset;
141             validKeywords[(int)Keywords.ContextConnection]              = DbConnectionStringKeywords.ContextConnection;
142             validKeywords[(int)Keywords.ConnectTimeout]                 = DbConnectionStringKeywords.ConnectTimeout;
143             validKeywords[(int)Keywords.CurrentLanguage]                = DbConnectionStringKeywords.CurrentLanguage;
144             validKeywords[(int)Keywords.DataSource]                     = DbConnectionStringKeywords.DataSource;
145             validKeywords[(int)Keywords.Encrypt]                        = DbConnectionStringKeywords.Encrypt;
146             validKeywords[(int)Keywords.Enlist]                         = DbConnectionStringKeywords.Enlist;
147             validKeywords[(int)Keywords.FailoverPartner]                = DbConnectionStringKeywords.FailoverPartner;
148             validKeywords[(int)Keywords.InitialCatalog]                 = DbConnectionStringKeywords.InitialCatalog;
149             validKeywords[(int)Keywords.IntegratedSecurity]             = DbConnectionStringKeywords.IntegratedSecurity;
150             validKeywords[(int)Keywords.LoadBalanceTimeout]             = DbConnectionStringKeywords.LoadBalanceTimeout;
151             validKeywords[(int)Keywords.MaxPoolSize]                    = DbConnectionStringKeywords.MaxPoolSize;
152             validKeywords[(int)Keywords.MinPoolSize]                    = DbConnectionStringKeywords.MinPoolSize;
153             validKeywords[(int)Keywords.MultipleActiveResultSets]       = DbConnectionStringKeywords.MultipleActiveResultSets;
154             validKeywords[(int)Keywords.MultiSubnetFailover]            = DbConnectionStringKeywords.MultiSubnetFailover;
155             validKeywords[(int)Keywords.TransparentNetworkIPResolution] = DbConnectionStringKeywords.TransparentNetworkIPResolution;
156 //          validKeywords[(int)Keywords.NamedConnection]                = DbConnectionStringKeywords.NamedConnection;
157             validKeywords[(int)Keywords.NetworkLibrary]                 = DbConnectionStringKeywords.NetworkLibrary;
158             validKeywords[(int)Keywords.PacketSize]                     = DbConnectionStringKeywords.PacketSize;
159             validKeywords[(int)Keywords.Password]                       = DbConnectionStringKeywords.Password;
160             validKeywords[(int)Keywords.PersistSecurityInfo]            = DbConnectionStringKeywords.PersistSecurityInfo;
161             validKeywords[(int)Keywords.Pooling]                        = DbConnectionStringKeywords.Pooling;
162             validKeywords[(int)Keywords.Replication]                    = DbConnectionStringKeywords.Replication;
163             validKeywords[(int)Keywords.TransactionBinding]             = DbConnectionStringKeywords.TransactionBinding;
164             validKeywords[(int)Keywords.TrustServerCertificate]         = DbConnectionStringKeywords.TrustServerCertificate;
165             validKeywords[(int)Keywords.TypeSystemVersion]              = DbConnectionStringKeywords.TypeSystemVersion;
166             validKeywords[(int)Keywords.UserID]                         = DbConnectionStringKeywords.UserID;
167             validKeywords[(int)Keywords.UserInstance]                   = DbConnectionStringKeywords.UserInstance;
168             validKeywords[(int)Keywords.WorkstationID]                  = DbConnectionStringKeywords.WorkstationID;
169             validKeywords[(int)Keywords.ConnectRetryCount]              = DbConnectionStringKeywords.ConnectRetryCount;
170             validKeywords[(int)Keywords.ConnectRetryInterval]           = DbConnectionStringKeywords.ConnectRetryInterval;
171             validKeywords[(int)Keywords.Authentication]                 = DbConnectionStringKeywords.Authentication;
172             validKeywords[(int)Keywords.ColumnEncryptionSetting]        = DbConnectionStringKeywords.ColumnEncryptionSetting;
173             _validKeywords = validKeywords;
174
175             Dictionary<string, Keywords> hash = new Dictionary<string, Keywords>(KeywordsCount + SqlConnectionString.SynonymCount, StringComparer.OrdinalIgnoreCase);
176             hash.Add(DbConnectionStringKeywords.ApplicationIntent,                                      Keywords.ApplicationIntent);
177             hash.Add(DbConnectionStringKeywords.ApplicationName,                                        Keywords.ApplicationName);
178             hash.Add(DbConnectionStringKeywords.AsynchronousProcessing,                         Keywords.AsynchronousProcessing);
179             hash.Add(DbConnectionStringKeywords.AttachDBFilename,                                       Keywords.AttachDBFilename);
180             hash.Add(DbConnectionStringKeywords.PoolBlockingPeriod,           Keywords.PoolBlockingPeriod);
181             hash.Add(DbConnectionStringKeywords.ConnectTimeout,                                         Keywords.ConnectTimeout);
182             hash.Add(DbConnectionStringKeywords.ConnectionReset,                                        Keywords.ConnectionReset);
183             hash.Add(DbConnectionStringKeywords.ContextConnection,                                      Keywords.ContextConnection);
184             hash.Add(DbConnectionStringKeywords.CurrentLanguage,                                        Keywords.CurrentLanguage);
185             hash.Add(DbConnectionStringKeywords.DataSource,                                                     Keywords.DataSource);
186             hash.Add(DbConnectionStringKeywords.Encrypt,                                                        Keywords.Encrypt);
187             hash.Add(DbConnectionStringKeywords.Enlist,                                                         Keywords.Enlist);
188             hash.Add(DbConnectionStringKeywords.FailoverPartner,                                        Keywords.FailoverPartner);
189             hash.Add(DbConnectionStringKeywords.InitialCatalog,                                         Keywords.InitialCatalog);
190             hash.Add(DbConnectionStringKeywords.IntegratedSecurity,                                     Keywords.IntegratedSecurity);
191             hash.Add(DbConnectionStringKeywords.LoadBalanceTimeout,                                     Keywords.LoadBalanceTimeout);
192             hash.Add(DbConnectionStringKeywords.MultipleActiveResultSets,                       Keywords.MultipleActiveResultSets);
193             hash.Add(DbConnectionStringKeywords.MaxPoolSize,                                            Keywords.MaxPoolSize);
194             hash.Add(DbConnectionStringKeywords.MinPoolSize,                                            Keywords.MinPoolSize);
195             hash.Add(DbConnectionStringKeywords.MultiSubnetFailover,                            Keywords.MultiSubnetFailover);
196             hash.Add(DbConnectionStringKeywords.TransparentNetworkIPResolution,         Keywords.TransparentNetworkIPResolution);
197 //          hash.Add(DbConnectionStringKeywords.NamedConnection,                                        Keywords.NamedConnection);
198             hash.Add(DbConnectionStringKeywords.NetworkLibrary,                                         Keywords.NetworkLibrary);
199             hash.Add(DbConnectionStringKeywords.PacketSize,                                                     Keywords.PacketSize);
200             hash.Add(DbConnectionStringKeywords.Password,                                                       Keywords.Password);
201             hash.Add(DbConnectionStringKeywords.PersistSecurityInfo,                            Keywords.PersistSecurityInfo);
202             hash.Add(DbConnectionStringKeywords.Pooling,                                                        Keywords.Pooling);
203             hash.Add(DbConnectionStringKeywords.Replication,                                            Keywords.Replication);
204             hash.Add(DbConnectionStringKeywords.TransactionBinding,                                     Keywords.TransactionBinding);
205             hash.Add(DbConnectionStringKeywords.TrustServerCertificate,                         Keywords.TrustServerCertificate);
206             hash.Add(DbConnectionStringKeywords.TypeSystemVersion,                                      Keywords.TypeSystemVersion);
207             hash.Add(DbConnectionStringKeywords.UserID,                                                         Keywords.UserID);
208             hash.Add(DbConnectionStringKeywords.UserInstance,                                           Keywords.UserInstance);
209             hash.Add(DbConnectionStringKeywords.WorkstationID,                                          Keywords.WorkstationID);
210             hash.Add(DbConnectionStringKeywords.ConnectRetryCount,                                      Keywords.ConnectRetryCount);
211             hash.Add(DbConnectionStringKeywords.ConnectRetryInterval,                           Keywords.ConnectRetryInterval);
212             hash.Add(DbConnectionStringKeywords.Authentication,                                         Keywords.Authentication);
213             hash.Add(DbConnectionStringKeywords.ColumnEncryptionSetting,                        Keywords.ColumnEncryptionSetting);
214
215             hash.Add(DbConnectionStringSynonyms.APP,                                                            Keywords.ApplicationName);
216             hash.Add(DbConnectionStringSynonyms.Async,                                                          Keywords.AsynchronousProcessing);
217             hash.Add(DbConnectionStringSynonyms.EXTENDEDPROPERTIES,                                     Keywords.AttachDBFilename);
218             hash.Add(DbConnectionStringSynonyms.INITIALFILENAME,                                        Keywords.AttachDBFilename);
219             hash.Add(DbConnectionStringSynonyms.CONNECTIONTIMEOUT,                                      Keywords.ConnectTimeout);
220             hash.Add(DbConnectionStringSynonyms.TIMEOUT,                                                        Keywords.ConnectTimeout);
221             hash.Add(DbConnectionStringSynonyms.LANGUAGE,                                                       Keywords.CurrentLanguage);
222             hash.Add(DbConnectionStringSynonyms.ADDR,                                                           Keywords.DataSource);
223             hash.Add(DbConnectionStringSynonyms.ADDRESS,                                                        Keywords.DataSource);
224             hash.Add(DbConnectionStringSynonyms.NETWORKADDRESS,                                         Keywords.DataSource);
225             hash.Add(DbConnectionStringSynonyms.SERVER,                                                         Keywords.DataSource);
226             hash.Add(DbConnectionStringSynonyms.DATABASE,                                                       Keywords.InitialCatalog);
227             hash.Add(DbConnectionStringSynonyms.TRUSTEDCONNECTION,                                      Keywords.IntegratedSecurity);
228             hash.Add(DbConnectionStringSynonyms.ConnectionLifetime,                                     Keywords.LoadBalanceTimeout);
229             hash.Add(DbConnectionStringSynonyms.NET,                                                            Keywords.NetworkLibrary);
230             hash.Add(DbConnectionStringSynonyms.NETWORK,                                                        Keywords.NetworkLibrary);
231             hash.Add(DbConnectionStringSynonyms.Pwd,                                                            Keywords.Password);
232             hash.Add(DbConnectionStringSynonyms.PERSISTSECURITYINFO,                            Keywords.PersistSecurityInfo);
233             hash.Add(DbConnectionStringSynonyms.UID,                                                            Keywords.UserID);
234             hash.Add(DbConnectionStringSynonyms.User,                                                           Keywords.UserID);
235             hash.Add(DbConnectionStringSynonyms.WSID,                                                           Keywords.WorkstationID);
236             Debug.Assert((KeywordsCount + SqlConnectionString.SynonymCount) == hash.Count, "initial expected size is incorrect");
237             _keywords = hash;
238
239         }
240
241         public SqlConnectionStringBuilder() : this((string)null) {
242         }
243
244         public SqlConnectionStringBuilder(string connectionString) : base() {
245             if (!ADP.IsEmpty(connectionString)) {
246                 ConnectionString = connectionString;
247             }
248         }
249
250         public override object this[string keyword] {
251             get {
252                 Keywords index = GetIndex(keyword);
253                 return GetAt(index);
254             }
255             set {
256                 if (null != value) {
257                     Keywords index = GetIndex(keyword);
258                     switch(index) {
259                     case Keywords.ApplicationIntent:                            this.ApplicationIntent = ConvertToApplicationIntent(keyword, value); break;
260                     case Keywords.ApplicationName:                                      ApplicationName = ConvertToString(value); break;
261                     case Keywords.AttachDBFilename:                                     AttachDBFilename = ConvertToString(value); break;
262                     case Keywords.CurrentLanguage:                                      CurrentLanguage = ConvertToString(value); break;
263                     case Keywords.DataSource:                                           DataSource = ConvertToString(value); break;
264                     case Keywords.FailoverPartner:                                      FailoverPartner = ConvertToString(value); break;
265                     case Keywords.InitialCatalog:                                       InitialCatalog = ConvertToString(value); break;
266 //                  case Keywords.NamedConnection:                                      NamedConnection = ConvertToString(value); break;
267                     case Keywords.NetworkLibrary:                                       NetworkLibrary = ConvertToString(value); break;
268                     case Keywords.Password:                                                     Password = ConvertToString(value); break;
269                     case Keywords.UserID:                                                       UserID = ConvertToString(value); break;
270                     case Keywords.TransactionBinding:                           TransactionBinding = ConvertToString(value); break;
271                     case Keywords.TypeSystemVersion:                            TypeSystemVersion = ConvertToString(value); break;
272                     case Keywords.WorkstationID:                                        WorkstationID = ConvertToString(value); break;
273
274                     case Keywords.ConnectTimeout:                                       ConnectTimeout = ConvertToInt32(value); break;
275                     case Keywords.LoadBalanceTimeout:                           LoadBalanceTimeout = ConvertToInt32(value); break;
276                     case Keywords.MaxPoolSize:                                          MaxPoolSize = ConvertToInt32(value); break;
277                     case Keywords.MinPoolSize:                                          MinPoolSize = ConvertToInt32(value); break;
278                     case Keywords.PacketSize:                                           PacketSize = ConvertToInt32(value); break;
279
280                     case Keywords.IntegratedSecurity:                           IntegratedSecurity = ConvertToIntegratedSecurity(value); break;
281
282                     case Keywords.Authentication:                                       Authentication = ConvertToAuthenticationType(keyword, value); break;
283                     case Keywords.ColumnEncryptionSetting:                      ColumnEncryptionSetting = ConvertToColumnEncryptionSetting(keyword, value); break;
284                     case Keywords.AsynchronousProcessing:                       AsynchronousProcessing = ConvertToBoolean(value); break;
285                     case Keywords.PoolBlockingPeriod:               PoolBlockingPeriod = ConvertToPoolBlockingPeriod(keyword, value); break;
286 #pragma warning disable 618 // Obsolete ConnectionReset
287                     case Keywords.ConnectionReset:                                      ConnectionReset = ConvertToBoolean(value); break;
288 #pragma warning restore 618
289                     case Keywords.ContextConnection:                            ContextConnection = ConvertToBoolean(value); break;
290                     case Keywords.Encrypt:                                                      Encrypt = ConvertToBoolean(value); break;
291                     case Keywords.TrustServerCertificate:                       TrustServerCertificate = ConvertToBoolean(value); break;
292                     case Keywords.Enlist:                                                       Enlist = ConvertToBoolean(value); break;
293                     case Keywords.MultipleActiveResultSets:                     MultipleActiveResultSets = ConvertToBoolean(value); break;
294                     case Keywords.MultiSubnetFailover:                          MultiSubnetFailover = ConvertToBoolean(value); break;
295                     case Keywords.TransparentNetworkIPResolution:       TransparentNetworkIPResolution = ConvertToBoolean(value); break;
296                     case Keywords.PersistSecurityInfo:                          PersistSecurityInfo = ConvertToBoolean(value); break;
297                     case Keywords.Pooling:                                                      Pooling = ConvertToBoolean(value); break;
298                     case Keywords.Replication:                                          Replication = ConvertToBoolean(value); break;
299                     case Keywords.UserInstance:                                         UserInstance = ConvertToBoolean(value); break;
300                     case Keywords.ConnectRetryCount:                            ConnectRetryCount = ConvertToInt32(value); break;
301                     case Keywords.ConnectRetryInterval:                         ConnectRetryInterval = ConvertToInt32(value); break;
302
303                     default:
304                         Debug.Assert(false, "unexpected keyword");
305                         throw ADP.KeywordNotSupported(keyword);
306                     }
307                 }
308                 else {
309                     Remove(keyword);
310                 }
311             }
312         }
313
314         [DisplayName(DbConnectionStringKeywords.ApplicationIntent)]
315         [ResCategoryAttribute(Res.DataCategory_Initialization)]
316         [ResDescriptionAttribute(Res.DbConnectionString_ApplicationIntent)]
317         [RefreshPropertiesAttribute(RefreshProperties.All)]
318         public ApplicationIntent ApplicationIntent {
319             get { return _applicationIntent; }
320             set {
321                 if (!DbConnectionStringBuilderUtil.IsValidApplicationIntentValue(value)) {
322                     throw ADP.InvalidEnumerationValue(typeof(ApplicationIntent), (int)value);
323                 }
324
325                 SetApplicationIntentValue(value);
326                 _applicationIntent = value;
327             }
328         }
329
330         [DisplayName(DbConnectionStringKeywords.ApplicationName)]
331         [ResCategoryAttribute(Res.DataCategory_Context)]
332         [ResDescriptionAttribute(Res.DbConnectionString_ApplicationName)]
333         [RefreshPropertiesAttribute(RefreshProperties.All)]
334         public string ApplicationName {
335             get { return _applicationName; }
336             set {
337                 SetValue(DbConnectionStringKeywords.ApplicationName, value);
338                 _applicationName = value;
339             }
340         }
341
342         [DisplayName(DbConnectionStringKeywords.AsynchronousProcessing)]
343         [ResCategoryAttribute(Res.DataCategory_Initialization)]
344         [ResDescriptionAttribute(Res.DbConnectionString_AsynchronousProcessing)]
345         [RefreshPropertiesAttribute(RefreshProperties.All)]
346         public bool AsynchronousProcessing {
347             get { return _asynchronousProcessing; }
348             set {
349                 SetValue(DbConnectionStringKeywords.AsynchronousProcessing, value);
350                 _asynchronousProcessing = value;
351             }
352         }
353
354         [DisplayName(DbConnectionStringKeywords.AttachDBFilename)]
355         [ResCategoryAttribute(Res.DataCategory_Source)]
356         [ResDescriptionAttribute(Res.DbConnectionString_AttachDBFilename)]
357         [RefreshPropertiesAttribute(RefreshProperties.All)]
358         // 
359         [Editor("System.Windows.Forms.Design.FileNameEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing)]
360         public string AttachDBFilename {
361             get { return _attachDBFilename; }
362             set {
363                 SetValue(DbConnectionStringKeywords.AttachDBFilename, value);
364                 _attachDBFilename = value;
365             }
366         }
367
368         [DisplayName(DbConnectionStringKeywords.PoolBlockingPeriod)]
369         [ResCategoryAttribute(Res.DataCategory_Pooling)]
370         [ResDescriptionAttribute(Res.DbConnectionString_PoolBlockingPeriod)]
371         [RefreshPropertiesAttribute(RefreshProperties.All)]
372         public PoolBlockingPeriod PoolBlockingPeriod
373         {
374             get { return _poolBlockingPeriod; }
375             set
376             {
377                 if (!DbConnectionStringBuilderUtil.IsValidPoolBlockingPeriodValue(value))
378                 {
379                     throw ADP.InvalidEnumerationValue(typeof(PoolBlockingPeriod), (int)value);
380                 }
381
382                 SetPoolBlockingPeriodValue(value);
383                 _poolBlockingPeriod = value;
384             }
385         }
386
387         [Browsable(false)]
388         [DisplayName(DbConnectionStringKeywords.ConnectionReset)]
389         [Obsolete("ConnectionReset has been deprecated.  SqlConnection will ignore the 'connection reset' keyword and always reset the connection")] // SQLPT 41700
390         [ResCategoryAttribute(Res.DataCategory_Pooling)]
391         [ResDescriptionAttribute(Res.DbConnectionString_ConnectionReset)]
392         [RefreshPropertiesAttribute(RefreshProperties.All)]
393         public bool ConnectionReset {
394             get { return _connectionReset; }
395             set {
396                 SetValue(DbConnectionStringKeywords.ConnectionReset, value);
397                 _connectionReset = value;
398             }
399         }
400
401         [DisplayName(DbConnectionStringKeywords.ContextConnection)]
402         [ResCategoryAttribute(Res.DataCategory_Source)]
403         [ResDescriptionAttribute(Res.DbConnectionString_ContextConnection)]
404         [RefreshPropertiesAttribute(RefreshProperties.All)]
405         public bool ContextConnection {
406             get { return _contextConnection; }
407             set {
408                 SetValue(DbConnectionStringKeywords.ContextConnection, value);
409                 _contextConnection = value;
410             }
411         }
412
413         [DisplayName(DbConnectionStringKeywords.ConnectTimeout)]
414         [ResCategoryAttribute(Res.DataCategory_Initialization)]
415         [ResDescriptionAttribute(Res.DbConnectionString_ConnectTimeout)]
416         [RefreshPropertiesAttribute(RefreshProperties.All)]
417         public int ConnectTimeout {
418             get { return _connectTimeout; }
419             set {
420                 if (value < 0) {
421                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.ConnectTimeout);
422                 }
423                 SetValue(DbConnectionStringKeywords.ConnectTimeout, value);
424                 _connectTimeout = value;
425             }
426         }
427
428         [DisplayName(DbConnectionStringKeywords.CurrentLanguage)]
429         [ResCategoryAttribute(Res.DataCategory_Initialization)]
430         [ResDescriptionAttribute(Res.DbConnectionString_CurrentLanguage)]
431         [RefreshPropertiesAttribute(RefreshProperties.All)]
432         public string CurrentLanguage {
433             get { return _currentLanguage; }
434             set {
435                 SetValue(DbConnectionStringKeywords.CurrentLanguage, value);
436                 _currentLanguage = value;
437             }
438         }
439
440         [DisplayName(DbConnectionStringKeywords.DataSource)]
441         [ResCategoryAttribute(Res.DataCategory_Source)]
442         [ResDescriptionAttribute(Res.DbConnectionString_DataSource)]
443         [RefreshProperties(RefreshProperties.All)]
444         [TypeConverter(typeof(SqlDataSourceConverter))]
445         public string DataSource {
446             get { return _dataSource; }
447             set {
448                 SetValue(DbConnectionStringKeywords.DataSource, value);
449                 _dataSource = value;
450             }
451         }
452
453         [DisplayName(DbConnectionStringKeywords.Encrypt)]
454         [ResCategoryAttribute(Res.DataCategory_Security)]
455         [ResDescriptionAttribute(Res.DbConnectionString_Encrypt)]
456         [RefreshPropertiesAttribute(RefreshProperties.All)]
457         public bool Encrypt {
458             get { return _encrypt; }
459             set {
460                 SetValue(DbConnectionStringKeywords.Encrypt, value);
461                 _encrypt = value;
462             }
463         }
464
465         [DisplayName(DbConnectionStringKeywords.ColumnEncryptionSetting)]
466         [ResCategoryAttribute(Res.DataCategory_Security)]
467         [ResDescriptionAttribute(Res.TCE_DbConnectionString_ColumnEncryptionSetting)]
468         [RefreshPropertiesAttribute(RefreshProperties.All)]
469         public SqlConnectionColumnEncryptionSetting ColumnEncryptionSetting {
470             get { return _columnEncryptionSetting; }
471             set {
472                 if (!DbConnectionStringBuilderUtil.IsValidColumnEncryptionSetting(value)) {
473                     throw ADP.InvalidEnumerationValue(typeof(SqlConnectionColumnEncryptionSetting), (int)value);
474                 }
475
476                  SetColumnEncryptionSettingValue(value);
477                 _columnEncryptionSetting = value;
478             }
479         }
480         
481         [DisplayName(DbConnectionStringKeywords.TrustServerCertificate)]
482         [ResCategoryAttribute(Res.DataCategory_Security)]
483         [ResDescriptionAttribute(Res.DbConnectionString_TrustServerCertificate)]
484         [RefreshPropertiesAttribute(RefreshProperties.All)]
485         public bool TrustServerCertificate {
486             get { return _trustServerCertificate; }
487             set {
488                 SetValue(DbConnectionStringKeywords.TrustServerCertificate, value);
489                 _trustServerCertificate = value;
490             }
491         }
492         
493         [DisplayName(DbConnectionStringKeywords.Enlist)]
494         [ResCategoryAttribute(Res.DataCategory_Pooling)]
495         [ResDescriptionAttribute(Res.DbConnectionString_Enlist)]
496         [RefreshPropertiesAttribute(RefreshProperties.All)]
497         public bool Enlist {
498             get { return _enlist; }
499             set {
500                 SetValue(DbConnectionStringKeywords.Enlist, value);
501                 _enlist = value;
502             }
503         }
504
505         [DisplayName(DbConnectionStringKeywords.FailoverPartner)]
506         [ResCategoryAttribute(Res.DataCategory_Source)]
507         [ResDescriptionAttribute(Res.DbConnectionString_FailoverPartner)]
508         [RefreshPropertiesAttribute(RefreshProperties.All)]
509         [TypeConverter(typeof(SqlDataSourceConverter))]
510         public string FailoverPartner {
511             get { return _failoverPartner; }
512             set {
513                 SetValue(DbConnectionStringKeywords.FailoverPartner, value);
514                 _failoverPartner= value;
515             }
516         }
517
518         [DisplayName(DbConnectionStringKeywords.InitialCatalog)]
519         [ResCategoryAttribute(Res.DataCategory_Source)]
520         [ResDescriptionAttribute(Res.DbConnectionString_InitialCatalog)]
521         [RefreshPropertiesAttribute(RefreshProperties.All)]
522         [TypeConverter(typeof(SqlInitialCatalogConverter))]
523         public string InitialCatalog {
524             get { return _initialCatalog; }
525             set {
526                 SetValue(DbConnectionStringKeywords.InitialCatalog, value);
527                 _initialCatalog = value;
528             }
529         }
530
531         [DisplayName(DbConnectionStringKeywords.IntegratedSecurity)]
532         [ResCategoryAttribute(Res.DataCategory_Security)]
533         [ResDescriptionAttribute(Res.DbConnectionString_IntegratedSecurity)]
534         [RefreshPropertiesAttribute(RefreshProperties.All)]
535         public bool IntegratedSecurity {
536             get { return _integratedSecurity; }
537             set {
538                 SetValue(DbConnectionStringKeywords.IntegratedSecurity, value);
539                 _integratedSecurity = value;
540             }
541         }
542
543         [DisplayName(DbConnectionStringKeywords.Authentication)]
544         [ResCategoryAttribute(Res.DataCategory_Security)]
545         [ResDescriptionAttribute(Res.DbConnectionString_Authentication)]
546         [RefreshPropertiesAttribute(RefreshProperties.All)]
547         public SqlAuthenticationMethod Authentication {
548             get { return _authentication; }
549             set {
550                 if (!DbConnectionStringBuilderUtil.IsValidAuthenticationTypeValue(value)) {
551                     throw ADP.InvalidEnumerationValue(typeof(SqlAuthenticationMethod), (int)value);
552                 }
553
554                 SetAuthenticationValue(value);
555                 _authentication = value;
556             }
557         }
558
559         [DisplayName(DbConnectionStringKeywords.LoadBalanceTimeout)]
560         [ResCategoryAttribute(Res.DataCategory_Pooling)]
561         [ResDescriptionAttribute(Res.DbConnectionString_LoadBalanceTimeout)]
562         [RefreshPropertiesAttribute(RefreshProperties.All)]
563         public int LoadBalanceTimeout {
564             get { return _loadBalanceTimeout; }
565             set {
566                 if (value < 0) {
567                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.LoadBalanceTimeout);
568                 }
569                 SetValue(DbConnectionStringKeywords.LoadBalanceTimeout, value);
570                 _loadBalanceTimeout = value;
571             }
572         }
573
574         [DisplayName(DbConnectionStringKeywords.MaxPoolSize)]
575         [ResCategoryAttribute(Res.DataCategory_Pooling)]
576         [ResDescriptionAttribute(Res.DbConnectionString_MaxPoolSize)]
577         [RefreshPropertiesAttribute(RefreshProperties.All)]
578         public int MaxPoolSize {
579             get { return _maxPoolSize; }
580             set {
581                 if (value < 1) {
582                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.MaxPoolSize);
583                 }
584                 SetValue(DbConnectionStringKeywords.MaxPoolSize, value);
585                 _maxPoolSize = value;
586             }
587         }
588
589         [DisplayName(DbConnectionStringKeywords.ConnectRetryCount)]
590         [ResCategoryAttribute(Res.DataCategory_ConnectionResilency)]
591         [ResDescriptionAttribute(Res.DbConnectionString_ConnectRetryCount)]
592         [RefreshPropertiesAttribute(RefreshProperties.All)]
593         public int ConnectRetryCount {
594             get { return _connectRetryCount; }
595             set {
596                 if ((value < 0) || (value>255)) {
597                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.ConnectRetryCount);
598                 }
599                 SetValue(DbConnectionStringKeywords.ConnectRetryCount, value);
600                 _connectRetryCount = value;
601             }
602         }
603
604         [DisplayName(DbConnectionStringKeywords.ConnectRetryInterval)]
605         [ResCategoryAttribute(Res.DataCategory_ConnectionResilency)]
606         [ResDescriptionAttribute(Res.DbConnectionString_ConnectRetryInterval)]
607         [RefreshPropertiesAttribute(RefreshProperties.All)]
608         public int ConnectRetryInterval {
609             get { return _connectRetryInterval; }
610             set {
611                 if ((value < 1) || (value > 60)) {
612                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.ConnectRetryInterval);
613                 }
614                 SetValue(DbConnectionStringKeywords.ConnectRetryInterval, value);
615                 _connectRetryInterval = value;
616             }
617         }
618
619
620
621         [DisplayName(DbConnectionStringKeywords.MinPoolSize)]
622         [ResCategoryAttribute(Res.DataCategory_Pooling)]
623         [ResDescriptionAttribute(Res.DbConnectionString_MinPoolSize)]
624         [RefreshPropertiesAttribute(RefreshProperties.All)]
625         public int MinPoolSize {
626             get { return _minPoolSize; }
627             set {
628                 if (value < 0) {
629                     throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.MinPoolSize);
630                 }
631                 SetValue(DbConnectionStringKeywords.MinPoolSize, value);
632                 _minPoolSize = value;
633             }
634         }
635
636         [DisplayName(DbConnectionStringKeywords.MultipleActiveResultSets)]
637         [ResCategoryAttribute(Res.DataCategory_Advanced)]
638         [ResDescriptionAttribute(Res.DbConnectionString_MultipleActiveResultSets)]
639         [RefreshPropertiesAttribute(RefreshProperties.All)]
640         public bool MultipleActiveResultSets {
641             get { return _multipleActiveResultSets; }
642             set {
643                 SetValue(DbConnectionStringKeywords.MultipleActiveResultSets, value);
644                 _multipleActiveResultSets = value;
645             }
646         }
647
648         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "Reviewed and Approved by UE")]
649         [DisplayName(DbConnectionStringKeywords.MultiSubnetFailover)]
650         [ResCategoryAttribute(Res.DataCategory_Source)]
651         [ResDescriptionAttribute(Res.DbConnectionString_MultiSubnetFailover)]
652         [RefreshPropertiesAttribute(RefreshProperties.All)]
653         public bool MultiSubnetFailover {
654             get { return _multiSubnetFailover; }
655             set {
656                 SetValue(DbConnectionStringKeywords.MultiSubnetFailover, value);
657                 _multiSubnetFailover = value;
658             }
659         }
660
661         [DisplayName(DbConnectionStringKeywords.TransparentNetworkIPResolution)]
662         [ResCategoryAttribute(Res.DataCategory_Source)]
663         [ResDescriptionAttribute(Res.DbConnectionString_TransparentNetworkIPResolution)]
664         [RefreshPropertiesAttribute(RefreshProperties.All)]
665         public bool TransparentNetworkIPResolution
666         {
667             get { return _transparentNetworkIPResolution; }
668             set {
669                 SetValue(DbConnectionStringKeywords.TransparentNetworkIPResolution, value);
670                 _transparentNetworkIPResolution = value;
671             }
672         }
673 /*
674         [DisplayName(DbConnectionStringKeywords.NamedConnection)]
675         [ResCategoryAttribute(Res.DataCategory_NamedConnectionString)]
676         [ResDescriptionAttribute(Res.DbConnectionString_NamedConnection)]
677         [RefreshPropertiesAttribute(RefreshProperties.All)]
678         [TypeConverter(typeof(NamedConnectionStringConverter))]
679         public string NamedConnection {
680             get { return _namedConnection; }
681             set {
682                 SetValue(DbConnectionStringKeywords.NamedConnection, value);
683                 _namedConnection = value;
684             }
685         }
686 */
687         [DisplayName(DbConnectionStringKeywords.NetworkLibrary)]
688         [ResCategoryAttribute(Res.DataCategory_Advanced)]
689         [ResDescriptionAttribute(Res.DbConnectionString_NetworkLibrary)]
690         [RefreshPropertiesAttribute(RefreshProperties.All)]
691         [TypeConverter(typeof(NetworkLibraryConverter))]
692         public string NetworkLibrary {
693             get { return _networkLibrary; }
694             set {
695                 if (null != value) {
696                     switch(value.Trim().ToLower(CultureInfo.InvariantCulture)) {
697                     case SqlConnectionString.NETLIB.AppleTalk:
698                         value = SqlConnectionString.NETLIB.AppleTalk;
699                         break;
700                     case SqlConnectionString.NETLIB.BanyanVines:
701                         value = SqlConnectionString.NETLIB.BanyanVines;
702                         break;
703                     case SqlConnectionString.NETLIB.IPXSPX:
704                         value = SqlConnectionString.NETLIB.IPXSPX;
705                         break;
706                     case SqlConnectionString.NETLIB.Multiprotocol:
707                         value = SqlConnectionString.NETLIB.Multiprotocol;
708                         break;
709                     case SqlConnectionString.NETLIB.NamedPipes:
710                         value = SqlConnectionString.NETLIB.NamedPipes;
711                         break;
712                     case SqlConnectionString.NETLIB.SharedMemory:
713                         value = SqlConnectionString.NETLIB.SharedMemory;
714                         break;
715                     case SqlConnectionString.NETLIB.TCPIP:
716                         value = SqlConnectionString.NETLIB.TCPIP;
717                         break;
718                     case SqlConnectionString.NETLIB.VIA:
719                         value = SqlConnectionString.NETLIB.VIA;
720                         break;
721                     default:
722                         throw ADP.InvalidConnectionOptionValue(DbConnectionStringKeywords.NetworkLibrary);
723                     }
724                 }
725                 SetValue(DbConnectionStringKeywords.NetworkLibrary, value);
726                 _networkLibrary = value;
727             }
728         }
729
730         [DisplayName(DbConnectionStringKeywords.PacketSize)]
731         [ResCategoryAttribute(Res.DataCategory_Advanced)]
732         [ResDescriptionAttribute(Res.DbConnectionString_PacketSize)]
733         [RefreshPropertiesAttribute(RefreshProperties.All)]
734         public int PacketSize {
735             get { return _packetSize; }
736             set {
737                 if ((value < TdsEnums.MIN_PACKET_SIZE) || (TdsEnums.MAX_PACKET_SIZE < value)) {
738                     throw SQL.InvalidPacketSizeValue();
739                 }
740                 SetValue(DbConnectionStringKeywords.PacketSize, value);
741                 _packetSize = value;
742             }
743         }
744
745         [DisplayName(DbConnectionStringKeywords.Password)]
746         [PasswordPropertyTextAttribute(true)]
747         [ResCategoryAttribute(Res.DataCategory_Security)]
748         [ResDescriptionAttribute(Res.DbConnectionString_Password)]
749         [RefreshPropertiesAttribute(RefreshProperties.All)]
750         public string Password {
751             get { return _password; }
752             set {
753                 SetValue(DbConnectionStringKeywords.Password, value);
754                 _password = value;
755             }
756         }
757
758         [DisplayName(DbConnectionStringKeywords.PersistSecurityInfo)]
759         [ResCategoryAttribute(Res.DataCategory_Security)]
760         [ResDescriptionAttribute(Res.DbConnectionString_PersistSecurityInfo)]
761         [RefreshPropertiesAttribute(RefreshProperties.All)]
762         public bool PersistSecurityInfo {
763             get { return _persistSecurityInfo; }
764             set {
765                 SetValue(DbConnectionStringKeywords.PersistSecurityInfo, value);
766                 _persistSecurityInfo = value;
767             }
768         }
769
770         [DisplayName(DbConnectionStringKeywords.Pooling)]
771         [ResCategoryAttribute(Res.DataCategory_Pooling)]
772         [ResDescriptionAttribute(Res.DbConnectionString_Pooling)]
773         [RefreshPropertiesAttribute(RefreshProperties.All)]
774         public bool Pooling {
775             get { return _pooling; }
776             set {
777                 SetValue(DbConnectionStringKeywords.Pooling, value);
778                 _pooling = value;
779             }
780         }
781
782         [DisplayName(DbConnectionStringKeywords.Replication)]
783         [ResCategoryAttribute(Res.DataCategory_Replication)]
784         [ResDescriptionAttribute(Res.DbConnectionString_Replication )]
785         [RefreshPropertiesAttribute(RefreshProperties.All)]
786         public bool Replication {
787             get { return _replication; }
788             set {
789                 SetValue(DbConnectionStringKeywords.Replication, value);
790                 _replication = value;
791             }
792         }
793
794         [DisplayName(DbConnectionStringKeywords.TransactionBinding)]
795         [ResCategoryAttribute(Res.DataCategory_Advanced)]
796         [ResDescriptionAttribute(Res.DbConnectionString_TransactionBinding)]
797         [RefreshPropertiesAttribute(RefreshProperties.All)]
798         public string TransactionBinding {
799             get { return _transactionBinding; }
800             set {
801                 SetValue(DbConnectionStringKeywords.TransactionBinding, value);
802                 _transactionBinding = value;
803             }
804         }
805
806         [DisplayName(DbConnectionStringKeywords.TypeSystemVersion)]
807         [ResCategoryAttribute(Res.DataCategory_Advanced)]
808         [ResDescriptionAttribute(Res.DbConnectionString_TypeSystemVersion)]
809         [RefreshPropertiesAttribute(RefreshProperties.All)]
810         public string TypeSystemVersion {
811             get { return _typeSystemVersion; }
812             set {
813                 SetValue(DbConnectionStringKeywords.TypeSystemVersion, value);
814                 _typeSystemVersion = value;
815             }
816         }
817
818         [DisplayName(DbConnectionStringKeywords.UserID)]
819         [ResCategoryAttribute(Res.DataCategory_Security)]
820         [ResDescriptionAttribute(Res.DbConnectionString_UserID)]
821         [RefreshPropertiesAttribute(RefreshProperties.All)]
822         public string UserID {
823             get { return _userID; }
824             set {
825                 SetValue(DbConnectionStringKeywords.UserID, value);
826                 _userID = value;
827             }
828         }
829
830         [DisplayName(DbConnectionStringKeywords.UserInstance)]
831         [ResCategoryAttribute(Res.DataCategory_Source)]
832         [ResDescriptionAttribute(Res.DbConnectionString_UserInstance)]
833         [RefreshPropertiesAttribute(RefreshProperties.All)]
834         public bool UserInstance {
835             get { return _userInstance; }
836             set {
837                 SetValue(DbConnectionStringKeywords.UserInstance, value);
838                 _userInstance = value;
839             }
840         }
841
842         [DisplayName(DbConnectionStringKeywords.WorkstationID)]
843         [ResCategoryAttribute(Res.DataCategory_Context)]
844         [ResDescriptionAttribute(Res.DbConnectionString_WorkstationID)]
845         [RefreshPropertiesAttribute(RefreshProperties.All)]
846         public string WorkstationID {
847             get { return _workstationID; }
848             set {
849                 SetValue(DbConnectionStringKeywords.WorkstationID, value);
850                 _workstationID = value;
851             }
852         }
853
854         public override bool IsFixedSize {
855             get {
856                 return true;
857             }
858         }
859
860         public override ICollection Keys {
861             get {
862                 return new System.Data.Common.ReadOnlyCollection<string>(_validKeywords);
863             }
864         }
865
866         public override ICollection Values {
867             get {
868                 // written this way so if the ordering of Keywords & _validKeywords changes
869                 // this is one less place to maintain
870                 object[] values = new object[_validKeywords.Length];
871                 for(int i = 0; i < values.Length; ++i) {
872                     values[i] = GetAt((Keywords)i);
873                 }
874                 return new System.Data.Common.ReadOnlyCollection<object>(values);
875             }
876         }
877
878         public override void Clear() {
879             base.Clear();
880             for(int i = 0; i < _validKeywords.Length; ++i) {
881                 Reset((Keywords)i);
882             }
883         }
884
885         public override bool ContainsKey(string keyword) {
886             ADP.CheckArgumentNull(keyword, "keyword");
887             return _keywords.ContainsKey(keyword);
888         }
889
890         private static bool ConvertToBoolean(object value) {
891             return DbConnectionStringBuilderUtil.ConvertToBoolean(value);
892         }
893         private static int ConvertToInt32(object value) {
894             return DbConnectionStringBuilderUtil.ConvertToInt32(value);
895         }
896         private static bool ConvertToIntegratedSecurity(object value) {
897             return DbConnectionStringBuilderUtil.ConvertToIntegratedSecurity(value);
898         }
899         private static string ConvertToString(object value) {
900             return DbConnectionStringBuilderUtil.ConvertToString(value);
901         }
902         private static ApplicationIntent ConvertToApplicationIntent(string keyword, object value) {
903             return DbConnectionStringBuilderUtil.ConvertToApplicationIntent(keyword, value);
904         }
905         private static SqlAuthenticationMethod ConvertToAuthenticationType(string keyword, object value) {
906             return DbConnectionStringBuilderUtil.ConvertToAuthenticationType(keyword, value);
907         }
908         private static PoolBlockingPeriod ConvertToPoolBlockingPeriod(string keyword, object value)
909         {
910             return DbConnectionStringBuilderUtil.ConvertToPoolBlockingPeriod(keyword, value);
911         }
912
913         /// <summary>
914         /// Convert to SqlConnectionColumnEncryptionSetting.
915         /// </summary>
916         /// <param name="keyword"></param>
917         /// <param name="value"></param>
918         private static SqlConnectionColumnEncryptionSetting ConvertToColumnEncryptionSetting(string keyword, object value) {
919             return DbConnectionStringBuilderUtil.ConvertToColumnEncryptionSetting(keyword, value);
920         }
921
922         internal override string ConvertValueToString(object value) {
923             if (value is SqlAuthenticationMethod) {
924                 return DbConnectionStringBuilderUtil.AuthenticationTypeToString((SqlAuthenticationMethod)value);
925             }
926             else {
927                 return base.ConvertValueToString(value);
928             }
929         }
930
931         private object GetAt(Keywords index) {
932             switch(index) {
933             case Keywords.ApplicationIntent:                            return this.ApplicationIntent;
934             case Keywords.ApplicationName:                                      return ApplicationName;
935             case Keywords.AsynchronousProcessing:                       return AsynchronousProcessing;
936             case Keywords.AttachDBFilename:                                     return AttachDBFilename;
937             case Keywords.PoolBlockingPeriod:         return PoolBlockingPeriod;
938             case Keywords.ConnectTimeout:                                       return ConnectTimeout;
939 #pragma warning disable 618 // Obsolete ConnectionReset
940             case Keywords.ConnectionReset:                                      return ConnectionReset;
941 #pragma warning restore 618
942             case Keywords.ContextConnection:                            return ContextConnection;
943             case Keywords.CurrentLanguage:                                      return CurrentLanguage;
944             case Keywords.DataSource:                                           return DataSource;
945             case Keywords.Encrypt:                                                      return Encrypt;
946             case Keywords.Enlist:                                                       return Enlist;
947             case Keywords.FailoverPartner:                                      return FailoverPartner;
948             case Keywords.InitialCatalog:                                       return InitialCatalog;
949             case Keywords.IntegratedSecurity:                           return IntegratedSecurity;
950             case Keywords.LoadBalanceTimeout:                           return LoadBalanceTimeout;
951             case Keywords.MultipleActiveResultSets:                     return MultipleActiveResultSets;
952             case Keywords.MaxPoolSize:                                          return MaxPoolSize;
953             case Keywords.MinPoolSize:                                          return MinPoolSize;
954             case Keywords.MultiSubnetFailover:                          return MultiSubnetFailover;
955             case Keywords.TransparentNetworkIPResolution:       return TransparentNetworkIPResolution;
956 //          case Keywords.NamedConnection:                                      return NamedConnection;
957             case Keywords.NetworkLibrary:                                       return NetworkLibrary;
958             case Keywords.PacketSize:                                           return PacketSize;
959             case Keywords.Password:                                                     return Password;
960             case Keywords.PersistSecurityInfo:                          return PersistSecurityInfo;
961             case Keywords.Pooling:                                                      return Pooling;
962             case Keywords.Replication:                                          return Replication;
963             case Keywords.TransactionBinding:                           return TransactionBinding;
964             case Keywords.TrustServerCertificate:                       return TrustServerCertificate;
965             case Keywords.TypeSystemVersion:                            return TypeSystemVersion;
966             case Keywords.UserID:                                                       return UserID;
967             case Keywords.UserInstance:                                         return UserInstance;
968             case Keywords.WorkstationID:                                        return WorkstationID;
969             case Keywords.ConnectRetryCount:                            return ConnectRetryCount;
970             case Keywords.ConnectRetryInterval:                         return ConnectRetryInterval;
971             case Keywords.Authentication:                                       return Authentication;
972             case Keywords.ColumnEncryptionSetting:                      return ColumnEncryptionSetting;
973             default:
974                 Debug.Assert(false, "unexpected keyword");
975                 throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
976             }
977         }
978
979         private Keywords GetIndex(string keyword) {
980             ADP.CheckArgumentNull(keyword, "keyword");
981             Keywords index;
982             if (_keywords.TryGetValue(keyword, out index)) {
983                 return index;
984             }
985             throw ADP.KeywordNotSupported(keyword);            
986         }
987
988         protected override void GetProperties(Hashtable propertyDescriptors) {
989             foreach(PropertyDescriptor reflected in TypeDescriptor.GetProperties(this, true)) {
990                 bool refreshOnChange = false;
991                 bool isReadonly = false;
992                 string displayName = reflected.DisplayName;
993
994                 // 'Password' & 'User ID' will be readonly if 'Integrated Security' is true
995                 if (DbConnectionStringKeywords.IntegratedSecurity == displayName) {
996                     refreshOnChange = true;
997                     isReadonly = reflected.IsReadOnly;
998                 }
999                 else if ((DbConnectionStringKeywords.Password == displayName) ||
1000                          (DbConnectionStringKeywords.UserID == displayName)) {
1001                      isReadonly = IntegratedSecurity;
1002                 }
1003                 else {
1004                     continue;
1005                 }
1006                 Attribute[] attributes = GetAttributesFromCollection(reflected.Attributes);
1007                 DbConnectionStringBuilderDescriptor descriptor = new DbConnectionStringBuilderDescriptor(reflected.Name,
1008                         reflected.ComponentType, reflected.PropertyType, isReadonly, attributes);
1009                 descriptor.RefreshOnChange = refreshOnChange;
1010                 propertyDescriptors[displayName] = descriptor;
1011             }
1012             base.GetProperties(propertyDescriptors);
1013         }
1014
1015         public override bool Remove(string keyword) {
1016             ADP.CheckArgumentNull(keyword, "keyword");
1017             Keywords index;
1018             if (_keywords.TryGetValue(keyword, out index)) {
1019                 if (base.Remove(_validKeywords[(int)index])) {
1020                     Reset(index);
1021                     return true;
1022                 }
1023             }
1024             return false;
1025         }
1026
1027         private void Reset(Keywords index) {
1028             switch(index) {
1029             case Keywords.ApplicationIntent:
1030                 _applicationIntent = DbConnectionStringDefaults.ApplicationIntent;
1031                 break;
1032             case Keywords.ApplicationName:
1033                 _applicationName = DbConnectionStringDefaults.ApplicationName;
1034                 break;
1035             case Keywords.AsynchronousProcessing:
1036                 _asynchronousProcessing = DbConnectionStringDefaults.AsynchronousProcessing;
1037                 break;
1038             case Keywords.AttachDBFilename:
1039                 _attachDBFilename = DbConnectionStringDefaults.AttachDBFilename;
1040                 break;
1041             case Keywords.Authentication:
1042                 _authentication = DbConnectionStringDefaults.Authentication;
1043                 break;
1044             case Keywords.PoolBlockingPeriod:
1045                 _poolBlockingPeriod = DbConnectionStringDefaults.PoolBlockingPeriod;
1046                 break;
1047               
1048             case Keywords.ConnectTimeout:
1049                 _connectTimeout = DbConnectionStringDefaults.ConnectTimeout;
1050                 break;
1051             case Keywords.ConnectionReset:
1052                 _connectionReset = DbConnectionStringDefaults.ConnectionReset;
1053                 break;
1054             case Keywords.ContextConnection:
1055                 _contextConnection = DbConnectionStringDefaults.ContextConnection;
1056                 break;
1057             case Keywords.CurrentLanguage:
1058                 _currentLanguage = DbConnectionStringDefaults.CurrentLanguage;
1059                 break;
1060             case Keywords.DataSource:
1061                 _dataSource = DbConnectionStringDefaults.DataSource;
1062                 break;
1063             case Keywords.Encrypt:
1064                 _encrypt = DbConnectionStringDefaults.Encrypt;
1065                 break;
1066             case Keywords.Enlist:
1067                 _enlist = DbConnectionStringDefaults.Enlist;
1068                 break;
1069             case Keywords.FailoverPartner:
1070                 _failoverPartner = DbConnectionStringDefaults.FailoverPartner;
1071                 break;
1072             case Keywords.InitialCatalog:
1073                 _initialCatalog = DbConnectionStringDefaults.InitialCatalog;
1074                 break;
1075             case Keywords.IntegratedSecurity:
1076                 _integratedSecurity = DbConnectionStringDefaults.IntegratedSecurity;
1077                 break;
1078             case Keywords.LoadBalanceTimeout:
1079                 _loadBalanceTimeout = DbConnectionStringDefaults.LoadBalanceTimeout;
1080                 break;
1081             case Keywords.MultipleActiveResultSets:
1082                 _multipleActiveResultSets = DbConnectionStringDefaults.MultipleActiveResultSets;
1083                 break;
1084             case Keywords.MaxPoolSize:
1085                 _maxPoolSize = DbConnectionStringDefaults.MaxPoolSize;
1086                 break;
1087             case Keywords.MinPoolSize:
1088                 _minPoolSize = DbConnectionStringDefaults.MinPoolSize;
1089                 break;
1090             case Keywords.MultiSubnetFailover:
1091                 _multiSubnetFailover = DbConnectionStringDefaults.MultiSubnetFailover;
1092                 break;
1093             case Keywords.TransparentNetworkIPResolution:
1094                 _transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
1095                     break;
1096 //          case Keywords.NamedConnection:
1097 //              _namedConnection = DbConnectionStringDefaults.NamedConnection;
1098 //              break;
1099             case Keywords.NetworkLibrary:
1100                 _networkLibrary = DbConnectionStringDefaults.NetworkLibrary;
1101                 break;
1102             case Keywords.PacketSize:
1103                 _packetSize = DbConnectionStringDefaults.PacketSize;
1104                 break;
1105             case Keywords.Password:
1106                 _password = DbConnectionStringDefaults.Password;
1107                 break;
1108             case Keywords.PersistSecurityInfo:
1109                 _persistSecurityInfo = DbConnectionStringDefaults.PersistSecurityInfo;
1110                 break;
1111             case Keywords.Pooling:
1112                 _pooling = DbConnectionStringDefaults.Pooling;
1113                 break;
1114             case Keywords.ConnectRetryCount:
1115                 _connectRetryCount = DbConnectionStringDefaults.ConnectRetryCount;
1116                 break;
1117             case Keywords.ConnectRetryInterval:
1118                 _connectRetryInterval = DbConnectionStringDefaults.ConnectRetryInterval;
1119                 break;
1120             case Keywords.Replication:
1121                 _replication = DbConnectionStringDefaults.Replication;
1122                 break;
1123             case Keywords.TransactionBinding:
1124                 _transactionBinding = DbConnectionStringDefaults.TransactionBinding;
1125                 break;
1126             case Keywords.TrustServerCertificate:
1127                 _trustServerCertificate = DbConnectionStringDefaults.TrustServerCertificate;
1128                 break;
1129             case Keywords.TypeSystemVersion:
1130                 _typeSystemVersion = DbConnectionStringDefaults.TypeSystemVersion;
1131                 break;
1132             case Keywords.UserID:
1133                 _userID = DbConnectionStringDefaults.UserID;
1134                 break;
1135             case Keywords.UserInstance:
1136                 _userInstance = DbConnectionStringDefaults.UserInstance;
1137                 break;
1138             case Keywords.WorkstationID:
1139                 _workstationID = DbConnectionStringDefaults.WorkstationID;
1140                 break;
1141             case Keywords.ColumnEncryptionSetting:
1142                 _columnEncryptionSetting = DbConnectionStringDefaults.ColumnEncryptionSetting;
1143                 break;
1144             default:
1145                 Debug.Assert(false, "unexpected keyword");
1146                 throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
1147             }
1148         }
1149
1150         private void SetValue(string keyword, bool value) {
1151             base[keyword] = value.ToString((System.IFormatProvider)null);
1152         }
1153         private void SetValue(string keyword, int value) {
1154             base[keyword] = value.ToString((System.IFormatProvider)null);
1155         }
1156         private void SetValue(string keyword, string value) {
1157             ADP.CheckArgumentNull(value, keyword);
1158             base[keyword] = value;
1159         }
1160         private void SetApplicationIntentValue(ApplicationIntent value) {
1161             Debug.Assert(DbConnectionStringBuilderUtil.IsValidApplicationIntentValue(value), "Invalid value for ApplicationIntent");
1162             base[DbConnectionStringKeywords.ApplicationIntent] = DbConnectionStringBuilderUtil.ApplicationIntentToString(value);
1163         }
1164         private void SetPoolBlockingPeriodValue(PoolBlockingPeriod value)
1165         {
1166             Debug.Assert(DbConnectionStringBuilderUtil.IsValidPoolBlockingPeriodValue(value), "Invalid value for PoolBlockingPeriod");
1167             base[DbConnectionStringKeywords.PoolBlockingPeriod] = DbConnectionStringBuilderUtil.PoolBlockingPeriodToString(value);
1168         }
1169         private void SetAuthenticationValue(SqlAuthenticationMethod value) {
1170             Debug.Assert(DbConnectionStringBuilderUtil.IsValidAuthenticationTypeValue(value), "Invalid value for AuthenticationType");
1171             base[DbConnectionStringKeywords.Authentication] = DbConnectionStringBuilderUtil.AuthenticationTypeToString(value);
1172         }
1173         private void SetColumnEncryptionSettingValue(SqlConnectionColumnEncryptionSetting value) {
1174             Debug.Assert(DbConnectionStringBuilderUtil.IsValidColumnEncryptionSetting(value), "Invalid value for SqlConnectionColumnEncryptionSetting");
1175             base[DbConnectionStringKeywords.ColumnEncryptionSetting] = DbConnectionStringBuilderUtil.ColumnEncryptionSettingToString(value);
1176         }
1177
1178         public override bool ShouldSerialize(string keyword) {
1179             ADP.CheckArgumentNull(keyword, "keyword");
1180             Keywords index;
1181             return _keywords.TryGetValue(keyword, out index) && base.ShouldSerialize(_validKeywords[(int)index]);
1182         }
1183
1184         public override bool TryGetValue(string keyword, out object value) {
1185             Keywords index;
1186             if (_keywords.TryGetValue(keyword, out index)) {
1187                 value = GetAt(index);
1188                 return true;
1189             }
1190             value = null;
1191             return false;
1192         }
1193
1194         private sealed class NetworkLibraryConverter : TypeConverter {
1195 //            private const string AppleTalk     = "Apple Talk (DBMSADSN)";  Invalid protocals
1196 //            private const string BanyanVines   = "Banyan VINES (DBMSVINN)";
1197 //            private const string IPXSPX        = "NWLink IPX/SPX (DBMSSPXN)";
1198 //            private const string Multiprotocol = "Multiprotocol (DBMSRPCN)";
1199             private const string NamedPipes    = "Named Pipes (DBNMPNTW)";   // valid protocols
1200             private const string SharedMemory  = "Shared Memory (DBMSLPCN)";
1201             private const string TCPIP         = "TCP/IP (DBMSSOCN)";
1202             private const string VIA           = "VIA (DBMSGNET)";
1203
1204             // these are correctly non-static, property grid will cache an instance
1205             private StandardValuesCollection _standardValues;
1206
1207             // converter classes should have public ctor
1208             public NetworkLibraryConverter() {
1209             }
1210
1211             public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
1212                 // Only know how to convert from a string
1213                 return ((typeof(string) == sourceType) || base.CanConvertFrom(context, sourceType));
1214             }
1215
1216             public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
1217                 string svalue = (value as string);
1218                 if (null != svalue) {
1219                     svalue = svalue.Trim();
1220                     if (StringComparer.OrdinalIgnoreCase.Equals(svalue, NamedPipes)) {
1221                         return SqlConnectionString.NETLIB.NamedPipes;
1222                     }
1223                     else if (StringComparer.OrdinalIgnoreCase.Equals(svalue, SharedMemory)) {
1224                         return SqlConnectionString.NETLIB.SharedMemory;
1225                     }
1226                     else if (StringComparer.OrdinalIgnoreCase.Equals(svalue, TCPIP)) {
1227                         return SqlConnectionString.NETLIB.TCPIP;
1228                     }
1229                     else if (StringComparer.OrdinalIgnoreCase.Equals(svalue, VIA)) {
1230                         return SqlConnectionString.NETLIB.VIA;
1231                     }
1232                     else {
1233                         return svalue;
1234                     }
1235                 }
1236                 return base.ConvertFrom(context, culture, value);
1237             }
1238
1239             public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
1240                 return ((typeof(string) == destinationType) || base.CanConvertTo(context, destinationType));
1241             }
1242
1243             public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
1244                 string svalue = (value as string);
1245                 if ((null != svalue) && (destinationType == typeof(string))) {
1246                     switch(svalue.Trim().ToLower(CultureInfo.InvariantCulture)) {
1247                     case SqlConnectionString.NETLIB.NamedPipes:
1248                         return NamedPipes;
1249                     case SqlConnectionString.NETLIB.SharedMemory:
1250                         return SharedMemory;
1251                     case SqlConnectionString.NETLIB.TCPIP:
1252                         return TCPIP;
1253                     case SqlConnectionString.NETLIB.VIA:
1254                         return VIA;
1255                     default:
1256                         return svalue;
1257                     }
1258                 }
1259                 return base.ConvertTo(context, culture, value, destinationType);
1260             }
1261
1262             public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
1263                 return true;
1264             }
1265
1266             public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
1267                 return false;
1268             }
1269
1270             public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
1271
1272                 SqlConnectionStringBuilder constr = null;
1273                 if (null != context) {
1274                     constr = (context.Instance as SqlConnectionStringBuilder);
1275                 }
1276
1277                 StandardValuesCollection standardValues = _standardValues;
1278                 if (null == standardValues) {
1279                     string[] names = new string[] {
1280                         NamedPipes,
1281                         SharedMemory,
1282                         TCPIP,
1283                         VIA,
1284                     };
1285                     standardValues = new StandardValuesCollection(names);
1286                     _standardValues = standardValues;
1287                 }
1288                 return standardValues;
1289             }
1290         }
1291
1292         private sealed class SqlDataSourceConverter : StringConverter {
1293
1294             private StandardValuesCollection _standardValues;
1295
1296             // converter classes should have public ctor
1297             public SqlDataSourceConverter() {
1298             }
1299
1300             public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
1301                 return true;
1302             }
1303
1304             public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
1305                 return false;
1306             }
1307
1308             public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
1309                 StandardValuesCollection dataSourceNames = _standardValues;
1310                 if (null == _standardValues) {
1311                     // Get the sources rowset for the SQLOLEDB enumerator
1312                     DataTable table = SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources();
1313                     DataColumn serverName = table.Columns[System.Data.Sql.SqlDataSourceEnumerator.ServerName];
1314                     DataColumn instanceName = table.Columns[System.Data.Sql.SqlDataSourceEnumerator.InstanceName];
1315                     DataRowCollection rows = table.Rows;
1316
1317                     string[] serverNames = new string[rows.Count];
1318                     for(int i = 0; i < serverNames.Length; ++i) {
1319                         string server   = rows[i][serverName] as string;
1320                         string instance = rows[i][instanceName] as string;
1321                         if ((null == instance) || (0 == instance.Length) || ("MSSQLSERVER" == instance)) {
1322                             serverNames[i] = server;
1323                         }
1324                         else {
1325                             serverNames[i] = server + @"\" + instance;
1326                         }
1327                     }
1328                     Array.Sort<string>(serverNames);
1329
1330                     // Create the standard values collection that contains the sources
1331                     dataSourceNames = new StandardValuesCollection(serverNames);
1332                     _standardValues = dataSourceNames;
1333                 }
1334                 return dataSourceNames;
1335             }
1336         }
1337
1338         private sealed class SqlInitialCatalogConverter : StringConverter {
1339
1340             // converter classes should have public ctor
1341             public SqlInitialCatalogConverter() {
1342             }
1343
1344             public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
1345                 return GetStandardValuesSupportedInternal(context);
1346             }
1347
1348             private bool GetStandardValuesSupportedInternal(ITypeDescriptorContext context) {
1349                 // Only say standard values are supported if the connection string has enough
1350                 // information set to instantiate a connection and retrieve a list of databases
1351                 bool flag = false;
1352                 if (null != context) {
1353                     SqlConnectionStringBuilder constr = (context.Instance as SqlConnectionStringBuilder);
1354                     if (null != constr) {
1355                         if ((0 < constr.DataSource.Length) && (constr.IntegratedSecurity || (0 < constr.UserID.Length))) {
1356                             flag = true;
1357                         }
1358                     }
1359                 }
1360                 return flag;
1361             }
1362
1363             public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
1364                 // Although theoretically this could be true, some people may want to just type in a name
1365                 return false;
1366             }
1367
1368             public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
1369                 // There can only be standard values if the connection string is in a state that might
1370                 // be able to instantiate a connection
1371                 if (GetStandardValuesSupportedInternal(context)) {
1372
1373                     // Create an array list to store the database names
1374                     List<string> values = new List<string>();
1375
1376                     try {
1377                         SqlConnectionStringBuilder constr = (SqlConnectionStringBuilder)context.Instance;
1378
1379                         // Create a connection
1380                         using(SqlConnection connection = new SqlConnection()) {
1381
1382                             // Create a basic connection string from current property values
1383                             connection.ConnectionString = constr.ConnectionString;
1384
1385                             // Try to open the connection
1386                             connection.Open();
1387
1388                             DataTable databaseTable = connection.GetSchema("DATABASES");
1389
1390                             foreach (DataRow row in databaseTable.Rows) {
1391                                 string dbName = (string)row["database_name"];
1392                                 values.Add(dbName);
1393                             }
1394                         }
1395                     }
1396                     catch(SqlException e) {
1397                         ADP.TraceExceptionWithoutRethrow(e);
1398                         // silently fail
1399                     }
1400
1401                     // Return values as a StandardValuesCollection
1402                     return new StandardValuesCollection(values);
1403                 }
1404                 return null;
1405             }
1406         }
1407
1408         sealed internal class SqlConnectionStringBuilderConverter : ExpandableObjectConverter {
1409
1410             // converter classes should have public ctor
1411             public SqlConnectionStringBuilderConverter() {
1412             }
1413
1414             override public bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
1415                 if (typeof(System.ComponentModel.Design.Serialization.InstanceDescriptor) == destinationType) {
1416                     return true;
1417                 }
1418                 return base.CanConvertTo(context, destinationType);
1419             }
1420
1421             override public object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
1422                 if (destinationType == null) {
1423                     throw ADP.ArgumentNull("destinationType");
1424                 }
1425                 if (typeof(System.ComponentModel.Design.Serialization.InstanceDescriptor) == destinationType) {
1426                     SqlConnectionStringBuilder obj = (value as SqlConnectionStringBuilder);
1427                     if (null != obj) {
1428                         return ConvertToInstanceDescriptor(obj);
1429                     }
1430                 }
1431                 return base.ConvertTo(context, culture, value, destinationType);
1432             }
1433
1434             private System.ComponentModel.Design.Serialization.InstanceDescriptor ConvertToInstanceDescriptor(SqlConnectionStringBuilder options) {
1435                 Type[] ctorParams = new Type[] { typeof(string) };
1436                 object[] ctorValues = new object[] { options.ConnectionString };
1437                 System.Reflection.ConstructorInfo ctor = typeof(SqlConnectionStringBuilder).GetConstructor(ctorParams);
1438                 return new System.ComponentModel.Design.Serialization.InstanceDescriptor(ctor, ctorValues);
1439             }
1440         }
1441     }
1442
1443 }
1444