SqlConnectionStringBuilder.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. //
  2. // System.Data.SqlClient.SqlConnectionStringBuilder.cs
  3. //
  4. // Author:
  5. // Sureshkumar T ([email protected])
  6. //
  7. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Text;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using System.Data;
  34. using System.Data.Common;
  35. using System.ComponentModel;
  36. namespace System.Data.SqlClient
  37. {
  38. [DefaultPropertyAttribute ("DataSource")]
  39. #if NET_2_0
  40. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlConnectionStringBuilderConverter, " + Consts.AssemblySystem_Data)]
  41. #endif
  42. public sealed class SqlConnectionStringBuilder : DbConnectionStringBuilder
  43. {
  44. private const string DEF_APPLICATIONNAME = ".NET SqlClient Data Provider";
  45. private const bool DEF_ASYNCHRONOUSPROCESSING = false;
  46. private const string DEF_ATTACHDBFILENAME = "";
  47. private const bool DEF_CONNECTIONRESET = true;
  48. private const int DEF_CONNECTTIMEOUT = 15;
  49. private const string DEF_CURRENTLANGUAGE = "";
  50. private const string DEF_DATASOURCE = "";
  51. private const bool DEF_ENCRYPT = false;
  52. private const bool DEF_ENLIST = false;
  53. private const string DEF_FAILOVERPARTNER = "";
  54. private const string DEF_INITIALCATALOG = "";
  55. private const bool DEF_INTEGRATEDSECURITY = false;
  56. private const int DEF_LOADBALANCETIMEOUT = 0;
  57. private const int DEF_MAXPOOLSIZE = 100;
  58. private const int DEF_MINPOOLSIZE = 0;
  59. private const bool DEF_MULTIPLEACTIVERESULTSETS = false;
  60. private const string DEF_NETWORKLIBRARY = "";
  61. private const int DEF_PACKETSIZE = 8000;
  62. private const string DEF_PASSWORD = "";
  63. private const bool DEF_PERSISTSECURITYINFO = false;
  64. private const bool DEF_POOLING = true;
  65. private const bool DEF_REPLICATION = false;
  66. private const string DEF_USERID = "";
  67. private const string DEF_WORKSTATIONID = "";
  68. private const string DEF_TYPESYSTEMVERSION = "Latest";
  69. private const bool DEF_TRUSTSERVERCERTIFICATE = false;
  70. private const bool DEF_USERINSTANCE = false;
  71. private const bool DEF_CONTEXTCONNECTION = false;
  72. #region // Fields
  73. private string _applicationName;
  74. private bool _asynchronousProcessing;
  75. private string _attachDBFilename;
  76. private bool _connectionReset;
  77. private int _connectTimeout;
  78. private string _currentLanguage;
  79. private string _dataSource;
  80. private bool _encrypt;
  81. private bool _enlist;
  82. private string _failoverPartner;
  83. private string _initialCatalog;
  84. private bool _integratedSecurity;
  85. private int _loadBalanceTimeout;
  86. private int _maxPoolSize;
  87. private int _minPoolSize;
  88. private bool _multipleActiveResultSets;
  89. private string _networkLibrary;
  90. private int _packetSize;
  91. private string _password;
  92. private bool _persistSecurityInfo;
  93. private bool _pooling;
  94. private bool _replication;
  95. private string _userID;
  96. private string _workstationID;
  97. private bool _trustServerCertificate;
  98. private string _typeSystemVersion;
  99. private bool _userInstance;
  100. private bool _contextConnection;
  101. private static Dictionary <string, string> _keywords; // for mapping duplicate keywords
  102. #endregion // Fields
  103. #region Constructors
  104. public SqlConnectionStringBuilder () : this (String.Empty)
  105. {
  106. }
  107. public SqlConnectionStringBuilder (string connectionString)
  108. {
  109. Init ();
  110. base.ConnectionString = connectionString;
  111. }
  112. static SqlConnectionStringBuilder ()
  113. {
  114. _keywords = new Dictionary <string, string> ();
  115. _keywords ["APP"] = "Application Name";
  116. _keywords ["APPLICATION NAME"] = "Application Name";
  117. _keywords ["ATTACHDBFILENAME"] = "AttachDBFilename";
  118. _keywords ["EXTENDED PROPERTIES"] = "Extended Properties";
  119. _keywords ["INITIAL FILE NAME"] = "Initial File Name";
  120. _keywords ["TIMEOUT"] = "Connect Timeout";
  121. _keywords ["CONNECT TIMEOUT"] = "Connect Timeout";
  122. _keywords ["CONNECTION TIMEOUT"] = "Connect Timeout";
  123. _keywords ["CONNECTION RESET"] = "Connection Reset";
  124. _keywords ["LANGUAGE"] = "Current Language";
  125. _keywords ["CURRENT LANGUAGE"] = "Current Language";
  126. _keywords ["DATA SOURCE"] = "Data Source";
  127. _keywords ["SERVER"] = "Data Source";
  128. _keywords ["ADDRESS"] = "Data Source";
  129. _keywords ["ADDR"] = "Data Source";
  130. _keywords ["NETWORK ADDRESS"] = "Data Source";
  131. _keywords ["ENCRYPT"] = "Encrypt";
  132. _keywords ["ENLIST"] = "Enlist";
  133. _keywords ["INITIAL CATALOG"] = "Initial Catalog";
  134. _keywords ["DATABASE"] = "Initial Catalog";
  135. _keywords ["INTEGRATED SECURITY"] = "Integrated Security";
  136. _keywords ["TRUSTED_CONNECTION"] = "Integrated Security";
  137. _keywords ["MAX POOL SIZE"] = "Max Pool Size";
  138. _keywords ["MIN POOL SIZE"] = "Min Pool Size";
  139. _keywords ["MULTIPLEACTIVERESULTSETS"] = "Multipleactiveresultset";
  140. _keywords ["ASYNCHRONOUS PROCESSING"] = "Asynchronous Processing";
  141. _keywords ["ASYNC"] = "Async";
  142. _keywords ["NET"] = "Network Library";
  143. _keywords ["NETWORK"] = "Network Library";
  144. _keywords ["NETWORK LIBRARY"] = "Network Library";
  145. _keywords ["PACKET SIZE"] = "Packet Size";
  146. _keywords ["PASSWORD"] = "Password";
  147. _keywords ["PWD"] = "Password";
  148. _keywords ["PERSISTSECURITYINFO"] = "Persist Security Info";
  149. _keywords ["PERSIST SECURITY INFO"] = "Persist Security Info";
  150. _keywords ["POOLING"] = "Pooling";
  151. _keywords ["UID"] = "User Id";
  152. _keywords ["USER"] = "User Id";
  153. _keywords ["USER ID"] = "User Id";
  154. _keywords ["WSID"] = "Workstation Id";
  155. _keywords ["WORKSTATION ID"] = "Workstation Id";
  156. _keywords ["USER INSTANCE"] = "User Instance";
  157. _keywords ["CONTEXT CONNECTION"] = "Context Connection";
  158. }
  159. #endregion // Constructors
  160. #region Properties
  161. [DisplayNameAttribute ("Application Name")]
  162. [RefreshPropertiesAttribute (RefreshProperties.All)]
  163. public string ApplicationName {
  164. get { return _applicationName; }
  165. set {
  166. base ["Application Name"] = value;
  167. _applicationName = value;
  168. }
  169. }
  170. [DisplayNameAttribute ("Asynchronous Processing")]
  171. [RefreshPropertiesAttribute (RefreshProperties.All)]
  172. public bool AsynchronousProcessing {
  173. get { return _asynchronousProcessing; }
  174. set {
  175. base ["Asynchronous Processing"] = value;
  176. _asynchronousProcessing = value;
  177. }
  178. }
  179. #if NET_2_0
  180. [Editor ("System.Windows.Forms.Design.FileNameEditor, " + Consts.AssemblySystem_Design,
  181. "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  182. #else
  183. [Editor ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, " + Consts.AssemblyMicrosoft_VSDesigner,
  184. "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  185. #endif
  186. [DisplayNameAttribute ("AttachDbFilename")]
  187. [RefreshPropertiesAttribute (RefreshProperties.All)]
  188. public string AttachDBFilename {
  189. get { return _attachDBFilename; }
  190. set {
  191. base ["AttachDbFilename"] = value;
  192. _attachDBFilename = value;
  193. }
  194. }
  195. [DisplayNameAttribute ("Connection Reset")]
  196. [RefreshPropertiesAttribute (RefreshProperties.All)]
  197. public bool ConnectionReset {
  198. get { return _connectionReset; }
  199. set {
  200. base ["Connection Reset"] = value;
  201. _connectionReset = value;
  202. }
  203. }
  204. [DisplayNameAttribute ("Connect Timeout")]
  205. [RefreshPropertiesAttribute (RefreshProperties.All)]
  206. public int ConnectTimeout {
  207. get { return _connectTimeout; }
  208. set {
  209. base ["Connect Timeout"] = value;
  210. _connectTimeout = value;
  211. }
  212. }
  213. [DisplayNameAttribute ("Current Language")]
  214. [RefreshPropertiesAttribute (RefreshProperties.All)]
  215. public string CurrentLanguage {
  216. get { return _currentLanguage; }
  217. set {
  218. base ["Current Language"] = value;
  219. _currentLanguage = value;
  220. }
  221. }
  222. [DisplayNameAttribute ("Data Source")]
  223. [RefreshPropertiesAttribute (RefreshProperties.All)]
  224. #if NET_2_0
  225. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, " + Consts.AssemblySystem_Data)]
  226. #endif
  227. public string DataSource {
  228. get { return _dataSource; }
  229. set {
  230. base ["Data Source"] = value;
  231. _dataSource = value;
  232. }
  233. }
  234. [DisplayNameAttribute ("Encrypt")]
  235. [RefreshPropertiesAttribute (RefreshProperties.All)]
  236. public bool Encrypt {
  237. get { return _encrypt; }
  238. set {
  239. base ["Encrypt"] = value;
  240. _encrypt = value;
  241. }
  242. }
  243. [DisplayNameAttribute ("Enlist")]
  244. [RefreshPropertiesAttribute (RefreshProperties.All)]
  245. public bool Enlist {
  246. get { return _enlist; }
  247. set {
  248. base ["Enlist"] = value;
  249. _enlist = value;
  250. }
  251. }
  252. [DisplayNameAttribute ("Failover Partner")]
  253. [RefreshPropertiesAttribute (RefreshProperties.All)]
  254. #if NET_2_0
  255. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, " + Consts.AssemblySystem_Data)]
  256. #endif
  257. public string FailoverPartner {
  258. get { return _failoverPartner; }
  259. set {
  260. base ["Failover Partner"] = value;
  261. _failoverPartner = value;
  262. }
  263. }
  264. [DisplayNameAttribute ("Initial Catalog")]
  265. [RefreshPropertiesAttribute (RefreshProperties.All)]
  266. #if NET_2_0
  267. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlInitialCatalogConverter, " + Consts.AssemblySystem_Data)]
  268. #endif
  269. public string InitialCatalog {
  270. get { return _initialCatalog; }
  271. set {
  272. base ["Initial Catalog"] = value;
  273. _initialCatalog = value;
  274. }
  275. }
  276. [DisplayNameAttribute ("Integrated Security")]
  277. [RefreshPropertiesAttribute (RefreshProperties.All)]
  278. public bool IntegratedSecurity {
  279. get { return _integratedSecurity; }
  280. set {
  281. base ["Integrated Security"] = value;
  282. _integratedSecurity = value;
  283. }
  284. }
  285. public override bool IsFixedSize {
  286. get { return true; }
  287. }
  288. public override object this [string keyword] {
  289. get {
  290. string mapped = MapKeyword (keyword);
  291. return base [mapped];
  292. }
  293. set {SetValue (keyword, value);}
  294. }
  295. public override ICollection Keys {
  296. get { return base.Keys; }
  297. }
  298. [DisplayNameAttribute ("Load Balance Timeout")]
  299. [RefreshPropertiesAttribute (RefreshProperties.All)]
  300. public int LoadBalanceTimeout {
  301. get { return _loadBalanceTimeout; }
  302. set {
  303. base ["Load Balance Timeout"] = value;
  304. _loadBalanceTimeout = value;
  305. }
  306. }
  307. [DisplayNameAttribute ("Max Pool Size")]
  308. [RefreshPropertiesAttribute (RefreshProperties.All)]
  309. public int MaxPoolSize {
  310. get { return _maxPoolSize; }
  311. set {
  312. base ["Max Pool Size"] = value;
  313. _maxPoolSize = value;
  314. }
  315. }
  316. [DisplayNameAttribute ("Min Pool Size")]
  317. [RefreshPropertiesAttribute (RefreshProperties.All)]
  318. public int MinPoolSize {
  319. get { return _minPoolSize; }
  320. set {
  321. base ["Min Pool Size"] = value;
  322. _minPoolSize = value;
  323. }
  324. }
  325. [DisplayNameAttribute ("MultipleActiveResultSets")]
  326. [RefreshPropertiesAttribute (RefreshProperties.All)]
  327. public bool MultipleActiveResultSets {
  328. get { return _multipleActiveResultSets; }
  329. set {
  330. base ["Multiple Active Resultsets"] = value;
  331. _multipleActiveResultSets = value;
  332. }
  333. }
  334. [DisplayNameAttribute ("Network Library")]
  335. [RefreshPropertiesAttribute (RefreshProperties.All)]
  336. #if NET_2_0
  337. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+NetworkLibraryConverter, " + Consts.AssemblySystem_Data)]
  338. #endif
  339. public string NetworkLibrary {
  340. get { return _networkLibrary; }
  341. set {
  342. base ["Network Library"] = value;
  343. _networkLibrary = value;
  344. }
  345. }
  346. [DisplayNameAttribute ("Packet Size")]
  347. [RefreshPropertiesAttribute (RefreshProperties.All)]
  348. public int PacketSize {
  349. get { return _packetSize; }
  350. set {
  351. base ["Packet Size"] = value;
  352. _packetSize = value;
  353. }
  354. }
  355. [DisplayNameAttribute ("Password")]
  356. [PasswordPropertyTextAttribute (true)]
  357. [RefreshPropertiesAttribute (RefreshProperties.All)]
  358. public string Password {
  359. get { return _password; }
  360. set {
  361. base ["Password"] = value;
  362. _password = value;
  363. }
  364. }
  365. [DisplayNameAttribute ("Persist Security Info")]
  366. [RefreshPropertiesAttribute (RefreshProperties.All)]
  367. public bool PersistSecurityInfo {
  368. get { return _persistSecurityInfo; }
  369. set {
  370. base ["Persist Security Info"] = value;
  371. _persistSecurityInfo = value;
  372. }
  373. }
  374. [DisplayNameAttribute ("Pooling")]
  375. [RefreshPropertiesAttribute (RefreshProperties.All)]
  376. public bool Pooling {
  377. get { return _pooling; }
  378. set {
  379. base ["Pooling"] = value;
  380. _pooling = value;
  381. }
  382. }
  383. [DisplayNameAttribute ("Replication")]
  384. [RefreshPropertiesAttribute (RefreshProperties.All)]
  385. public bool Replication {
  386. get { return _replication; }
  387. set {
  388. base ["Replication"] = value;
  389. _replication = value;
  390. }
  391. }
  392. [DisplayNameAttribute ("User ID")]
  393. [RefreshPropertiesAttribute (RefreshProperties.All)]
  394. public string UserID {
  395. get { return _userID; }
  396. set {
  397. base ["User Id"]= value;
  398. _userID = value;
  399. }
  400. }
  401. public override ICollection Values {
  402. get { return base.Values; }
  403. }
  404. [DisplayNameAttribute ("Workstation ID")]
  405. [RefreshPropertiesAttribute (RefreshProperties.All)]
  406. public string WorkstationID {
  407. get { return _workstationID; }
  408. set {
  409. base ["Workstation Id"] = value;
  410. _workstationID = value;
  411. }
  412. }
  413. [DisplayNameAttribute ("TrustServerCertificate")]
  414. [RefreshProperties (RefreshProperties.All)]
  415. public bool TrustServerCertificate {
  416. get { return _trustServerCertificate; }
  417. set {
  418. base ["Trust Server Certificate"] = value;
  419. _trustServerCertificate = value;
  420. }
  421. }
  422. [DisplayNameAttribute ("Type System Version")]
  423. [RefreshProperties (RefreshProperties.All)]
  424. public string TypeSystemVersion {
  425. get { return _typeSystemVersion; }
  426. set {
  427. base ["Type System Version"] = value;
  428. _typeSystemVersion = value;
  429. }
  430. }
  431. [DisplayNameAttribute ("User Instance")]
  432. [RefreshProperties (RefreshProperties.All)]
  433. public bool UserInstance {
  434. get { return _userInstance; }
  435. set {
  436. base ["User Instance"] = value;
  437. _userInstance = value;
  438. }
  439. }
  440. [RefreshPropertiesAttribute (RefreshProperties.All)]
  441. [DisplayNameAttribute ("Context Connection")]
  442. public bool ContextConnection {
  443. get { return _contextConnection; }
  444. set {
  445. base ["Context Connection"] = value;
  446. _contextConnection = value;
  447. }
  448. }
  449. #endregion // Properties
  450. #region Methods
  451. private void Init ()
  452. {
  453. _applicationName = DEF_APPLICATIONNAME;
  454. _asynchronousProcessing = DEF_ASYNCHRONOUSPROCESSING;
  455. _attachDBFilename = DEF_ATTACHDBFILENAME;
  456. _connectionReset = DEF_CONNECTIONRESET;
  457. _connectTimeout = DEF_CONNECTTIMEOUT;
  458. _currentLanguage = DEF_CURRENTLANGUAGE;
  459. _dataSource = DEF_DATASOURCE;
  460. _encrypt = DEF_ENCRYPT;
  461. _enlist = DEF_ENLIST;
  462. _failoverPartner = DEF_FAILOVERPARTNER;
  463. _initialCatalog = DEF_INITIALCATALOG;
  464. _integratedSecurity = DEF_INTEGRATEDSECURITY;
  465. _loadBalanceTimeout = DEF_LOADBALANCETIMEOUT;
  466. _maxPoolSize = DEF_MAXPOOLSIZE;
  467. _minPoolSize = DEF_MINPOOLSIZE;
  468. _multipleActiveResultSets= DEF_MULTIPLEACTIVERESULTSETS;
  469. _networkLibrary = DEF_NETWORKLIBRARY;
  470. _packetSize = DEF_PACKETSIZE;
  471. _password = DEF_PASSWORD;
  472. _persistSecurityInfo = DEF_PERSISTSECURITYINFO;
  473. _pooling = DEF_POOLING;
  474. _replication = DEF_REPLICATION;
  475. _userID = DEF_USERID;
  476. _workstationID = DEF_WORKSTATIONID;
  477. _trustServerCertificate = DEF_TRUSTSERVERCERTIFICATE;
  478. _typeSystemVersion = DEF_TYPESYSTEMVERSION;
  479. _userInstance = DEF_USERINSTANCE;
  480. _contextConnection = DEF_CONTEXTCONNECTION;
  481. }
  482. public override void Clear ()
  483. {
  484. base.Clear ();
  485. Init ();
  486. }
  487. public override bool ContainsKey (string keyword)
  488. {
  489. keyword = keyword.ToUpper ().Trim ();
  490. if (_keywords.ContainsKey (keyword))
  491. return base.ContainsKey (_keywords [keyword]);
  492. return false;
  493. }
  494. public override bool Remove (string keyword)
  495. {
  496. if (!ContainsKey (keyword))
  497. return false;
  498. this [keyword] = null;
  499. return true;
  500. }
  501. [MonoNotSupported ("")] // Note that base.ShouldSerialize() is called but not implemented
  502. public override bool ShouldSerialize (string keyword)
  503. {
  504. if (!ContainsKey (keyword))
  505. return false;
  506. keyword = keyword.ToUpper ().Trim ();
  507. // Assuming passwords cannot be serialized.
  508. if (_keywords [keyword] == "Password")
  509. return false;
  510. return base.ShouldSerialize (_keywords [keyword]);
  511. }
  512. public override bool TryGetValue (string keyword, out object value)
  513. {
  514. if (! ContainsKey (keyword)) {
  515. value = String.Empty;
  516. return false;
  517. }
  518. return base.TryGetValue (_keywords [keyword.ToUpper ().Trim ()], out value);
  519. }
  520. #endregion // Methods
  521. #region Private Methods
  522. private string MapKeyword (string keyword)
  523. {
  524. keyword = keyword.ToUpper ().Trim ();
  525. if (! _keywords.ContainsKey (keyword))
  526. throw new ArgumentException("Keyword not supported :" + keyword);
  527. return _keywords [keyword];
  528. }
  529. private void SetValue (string key, object value)
  530. {
  531. if (key == null)
  532. throw new ArgumentNullException ("key cannot be null!");
  533. string mappedKey = MapKeyword (key);
  534. switch (mappedKey.ToUpper ().Trim ()) {
  535. case "APPLICATION NAME" :
  536. if (value == null) {
  537. _applicationName = DEF_APPLICATIONNAME;
  538. base.Remove (mappedKey);
  539. } else
  540. this.ApplicationName = value.ToString ();
  541. break;
  542. case "ATTACHDBFILENAME" :
  543. throw new NotImplementedException ("Attachable database support is " +
  544. "not implemented.");
  545. case "CONNECT TIMEOUT" :
  546. if (value == null) {
  547. _connectTimeout = DEF_CONNECTTIMEOUT;
  548. base.Remove (mappedKey);
  549. } else
  550. this.ConnectTimeout = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  551. break;
  552. case "CONNECTION LIFETIME" :
  553. break;
  554. case "CONNECTION RESET" :
  555. if (value == null) {
  556. _connectionReset = DEF_CONNECTIONRESET;
  557. base.Remove (mappedKey);
  558. } else
  559. this.ConnectionReset = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  560. break;
  561. case "CURRENT LANGUAGE" :
  562. if (value == null) {
  563. _currentLanguage = DEF_CURRENTLANGUAGE;
  564. base.Remove (mappedKey);
  565. } else
  566. this.CurrentLanguage = value.ToString ();
  567. break;
  568. case "CONTEXT CONNECTION" :
  569. if (value == null) {
  570. _contextConnection = DEF_CONTEXTCONNECTION;
  571. base.Remove (mappedKey);
  572. } else
  573. this.ContextConnection = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  574. break;
  575. case "DATA SOURCE" :
  576. if (value == null) {
  577. _dataSource = DEF_DATASOURCE;
  578. base.Remove (mappedKey);
  579. } else
  580. this.DataSource = value.ToString ();
  581. break;
  582. case "ENCRYPT":
  583. if (value == null) {
  584. _encrypt = DEF_ENCRYPT;
  585. base.Remove (mappedKey);
  586. }else if (DbConnectionStringBuilderHelper.ConvertToBoolean(value))
  587. throw new NotImplementedException("SSL encryption for"
  588. + " data sent between client and server is not"
  589. + " implemented.");
  590. break;
  591. case "ENLIST" :
  592. if (value == null) {
  593. _enlist = DEF_ENLIST;
  594. base.Remove (mappedKey);
  595. } else if ( ! DbConnectionStringBuilderHelper.ConvertToBoolean(value))
  596. throw new NotImplementedException("Disabling the automatic"
  597. + " enlistment of connections in the thread's current"
  598. + " transaction context is not implemented.");
  599. break;
  600. case "INITIAL CATALOG" :
  601. if (value == null) {
  602. _initialCatalog = DEF_INITIALCATALOG;
  603. base.Remove (mappedKey);
  604. } else
  605. this.InitialCatalog = value.ToString ();
  606. break;
  607. case "INTEGRATED SECURITY" :
  608. if (value == null) {
  609. _integratedSecurity = DEF_INTEGRATEDSECURITY;
  610. base.Remove (mappedKey);
  611. } else
  612. this.IntegratedSecurity = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  613. break;
  614. case "MAX POOL SIZE" :
  615. if (value == null) {
  616. _maxPoolSize = DEF_MAXPOOLSIZE;
  617. base.Remove (mappedKey);
  618. } else
  619. this.MaxPoolSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  620. break;
  621. case "MIN POOL SIZE" :
  622. if (value == null) {
  623. _minPoolSize = DEF_MINPOOLSIZE;
  624. base.Remove (mappedKey);
  625. } else
  626. this.MinPoolSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  627. break;
  628. case "MULTIPLEACTIVERESULTSETS":
  629. if (value == null) {
  630. _multipleActiveResultSets = DEF_MULTIPLEACTIVERESULTSETS;
  631. base.Remove (mappedKey);
  632. } else if ( DbConnectionStringBuilderHelper.ConvertToBoolean (value))
  633. throw new NotImplementedException ("MARS is not yet implemented!");
  634. break;
  635. case "ASYNCHRONOUS PROCESSING" :
  636. if (value == null) {
  637. _asynchronousProcessing = DEF_ASYNCHRONOUSPROCESSING;
  638. base.Remove (mappedKey);
  639. } else
  640. this.AsynchronousProcessing = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  641. break;
  642. case "NETWORK LIBRARY" :
  643. if (value == null) {
  644. _networkLibrary = DEF_NETWORKLIBRARY;
  645. base.Remove (mappedKey);
  646. } else {
  647. if (!value.ToString ().ToUpper ().Equals ("DBMSSOCN"))
  648. throw new ArgumentException ("Unsupported network library.");
  649. this.NetworkLibrary = value.ToString ().ToLower ();
  650. }
  651. break;
  652. case "PACKET SIZE" :
  653. if (value == null) {
  654. _packetSize = DEF_PACKETSIZE;
  655. base.Remove (mappedKey);
  656. } else
  657. this.PacketSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  658. break;
  659. case "PASSWORD" :
  660. if (value == null) {
  661. _password = DEF_PASSWORD;
  662. base.Remove (mappedKey);
  663. } else
  664. this.Password = value.ToString ();
  665. break;
  666. case "PERSIST SECURITY INFO" :
  667. if (value == null) {
  668. _persistSecurityInfo = DEF_PERSISTSECURITYINFO;
  669. base.Remove (mappedKey);
  670. } else if (DbConnectionStringBuilderHelper.ConvertToBoolean (value))
  671. throw new NotImplementedException ("Persisting security info" +
  672. " is not yet implemented");
  673. break;
  674. case "POOLING" :
  675. if (value == null) {
  676. _pooling = DEF_POOLING;
  677. base.Remove (mappedKey);
  678. } else
  679. this.Pooling = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  680. break;
  681. case "USER ID" :
  682. if (value == null) {
  683. _userID = DEF_USERID;
  684. base.Remove (mappedKey);
  685. } else
  686. this.UserID = value.ToString ();
  687. break;
  688. case "USER INSTANCE" :
  689. if (value == null) {
  690. _userInstance = DEF_USERINSTANCE;
  691. base.Remove (mappedKey);
  692. } else
  693. this.UserInstance = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  694. break;
  695. case "WORKSTATION ID" :
  696. if (value == null) {
  697. _workstationID = DEF_WORKSTATIONID;
  698. base.Remove (mappedKey);
  699. } else
  700. this.WorkstationID = value.ToString ();
  701. break;
  702. default :
  703. throw new ArgumentException("Keyword not supported :" + key);
  704. }
  705. }
  706. #endregion // Private Methods
  707. }
  708. }
  709. #endif // NET_2_0