PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/System.Data/System.Data.SqlClient/SqlConnectionStringBuilder.cs

https://bitbucket.org/danipen/mono
C# | 881 lines | 795 code | 56 blank | 30 comment | 78 complexity | 1852b4e7a687d566020dd21d3941139d MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // System.Data.SqlClient.SqlConnectionStringBuilder.cs
  3. //
  4. // Author:
  5. // Sureshkumar T (tsureshkumar@novell.com)
  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.Collections.ObjectModel;
  34. using System.Data;
  35. using System.Data.Common;
  36. using System.ComponentModel;
  37. namespace System.Data.SqlClient
  38. {
  39. [DefaultPropertyAttribute ("DataSource")]
  40. #if NET_2_0
  41. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlConnectionStringBuilderConverter, " + Consts.AssemblySystem_Data)]
  42. #endif
  43. public sealed class SqlConnectionStringBuilder : DbConnectionStringBuilder
  44. {
  45. private const string DEF_APPLICATIONNAME = ".NET SqlClient Data Provider";
  46. private const bool DEF_ASYNCHRONOUSPROCESSING = false;
  47. private const string DEF_ATTACHDBFILENAME = "";
  48. private const bool DEF_CONNECTIONRESET = true;
  49. private const int DEF_CONNECTTIMEOUT = 15;
  50. private const string DEF_CURRENTLANGUAGE = "";
  51. private const string DEF_DATASOURCE = "";
  52. private const bool DEF_ENCRYPT = false;
  53. private const bool DEF_ENLIST = false;
  54. private const string DEF_FAILOVERPARTNER = "";
  55. private const string DEF_INITIALCATALOG = "";
  56. private const bool DEF_INTEGRATEDSECURITY = false;
  57. private const int DEF_LOADBALANCETIMEOUT = 0;
  58. private const int DEF_MAXPOOLSIZE = 100;
  59. private const int DEF_MINPOOLSIZE = 0;
  60. private const bool DEF_MULTIPLEACTIVERESULTSETS = false;
  61. private const string DEF_NETWORKLIBRARY = "";
  62. private const int DEF_PACKETSIZE = 8000;
  63. private const string DEF_PASSWORD = "";
  64. private const bool DEF_PERSISTSECURITYINFO = false;
  65. private const bool DEF_POOLING = true;
  66. private const bool DEF_REPLICATION = false;
  67. private const string DEF_USERID = "";
  68. private const string DEF_WORKSTATIONID = "";
  69. private const string DEF_TYPESYSTEMVERSION = "Latest";
  70. private const bool DEF_TRUSTSERVERCERTIFICATE = false;
  71. private const bool DEF_USERINSTANCE = false;
  72. private const bool DEF_CONTEXTCONNECTION = false;
  73. private const string DEF_TRANSACTIONBINDING = "Implicit Unbind";
  74. #region // Fields
  75. private string _applicationName;
  76. private bool _asynchronousProcessing;
  77. private string _attachDBFilename;
  78. private bool _connectionReset;
  79. private int _connectTimeout;
  80. private string _currentLanguage;
  81. private string _dataSource;
  82. private bool _encrypt;
  83. private bool _enlist;
  84. private string _failoverPartner;
  85. private string _initialCatalog;
  86. private bool _integratedSecurity;
  87. private int _loadBalanceTimeout;
  88. private int _maxPoolSize;
  89. private int _minPoolSize;
  90. private bool _multipleActiveResultSets;
  91. private string _networkLibrary;
  92. private int _packetSize;
  93. private string _password;
  94. private bool _persistSecurityInfo;
  95. private bool _pooling;
  96. private bool _replication;
  97. private string _userID;
  98. private string _workstationID;
  99. private bool _trustServerCertificate;
  100. private string _typeSystemVersion;
  101. private bool _userInstance;
  102. private bool _contextConnection;
  103. private string _transactionBinding;
  104. private static Dictionary <string, string> _keywords; // for mapping duplicate keywords
  105. private static Dictionary <string, object> _defaults;
  106. #endregion // Fields
  107. #region Constructors
  108. public SqlConnectionStringBuilder () : this (String.Empty)
  109. {
  110. }
  111. public SqlConnectionStringBuilder (string connectionString)
  112. {
  113. Init ();
  114. base.ConnectionString = connectionString;
  115. }
  116. static SqlConnectionStringBuilder ()
  117. {
  118. _keywords = new Dictionary <string, string> ();
  119. _keywords ["APP"] = "Application Name";
  120. _keywords ["APPLICATION NAME"] = "Application Name";
  121. _keywords ["ATTACHDBFILENAME"] = "AttachDbFilename";
  122. _keywords ["EXTENDED PROPERTIES"] = "Extended Properties";
  123. _keywords ["INITIAL FILE NAME"] = "Initial File Name";
  124. _keywords ["TIMEOUT"] = "Connect Timeout";
  125. _keywords ["CONNECT TIMEOUT"] = "Connect Timeout";
  126. _keywords ["CONNECTION TIMEOUT"] = "Connect Timeout";
  127. _keywords ["CONNECTION RESET"] = "Connection Reset";
  128. _keywords ["LANGUAGE"] = "Current Language";
  129. _keywords ["CURRENT LANGUAGE"] = "Current Language";
  130. _keywords ["DATA SOURCE"] = "Data Source";
  131. _keywords ["SERVER"] = "Data Source";
  132. _keywords ["ADDRESS"] = "Data Source";
  133. _keywords ["ADDR"] = "Data Source";
  134. _keywords ["NETWORK ADDRESS"] = "Data Source";
  135. _keywords ["ENCRYPT"] = "Encrypt";
  136. _keywords ["ENLIST"] = "Enlist";
  137. _keywords ["INITIAL CATALOG"] = "Initial Catalog";
  138. _keywords ["DATABASE"] = "Initial Catalog";
  139. _keywords ["INTEGRATED SECURITY"] = "Integrated Security";
  140. _keywords ["TRUSTED_CONNECTION"] = "Integrated Security";
  141. _keywords ["MAX POOL SIZE"] = "Max Pool Size";
  142. _keywords ["MIN POOL SIZE"] = "Min Pool Size";
  143. _keywords ["MULTIPLEACTIVERESULTSETS"] = "MultipleActiveResultSets";
  144. _keywords ["ASYNCHRONOUS PROCESSING"] = "Asynchronous Processing";
  145. _keywords ["ASYNC"] = "Async";
  146. _keywords ["NET"] = "Network Library";
  147. _keywords ["NETWORK"] = "Network Library";
  148. _keywords ["NETWORK LIBRARY"] = "Network Library";
  149. _keywords ["PACKET SIZE"] = "Packet Size";
  150. _keywords ["PASSWORD"] = "Password";
  151. _keywords ["PWD"] = "Password";
  152. _keywords ["PERSISTSECURITYINFO"] = "Persist Security Info";
  153. _keywords ["PERSIST SECURITY INFO"] = "Persist Security Info";
  154. _keywords ["POOLING"] = "Pooling";
  155. _keywords ["UID"] = "User ID";
  156. _keywords ["USER"] = "User ID";
  157. _keywords ["USER ID"] = "User ID";
  158. _keywords ["WSID"] = "Workstation ID";
  159. _keywords ["WORKSTATION ID"] = "Workstation ID";
  160. _keywords ["USER INSTANCE"] = "User Instance";
  161. _keywords ["CONTEXT CONNECTION"] = "Context Connection";
  162. _keywords ["TRANSACTION BINDING"] = "Transaction Binding";
  163. _keywords ["FAILOVER PARTNER"] = "Failover Partner";
  164. _keywords ["REPLICATION"] = "Replication";
  165. _keywords ["TRUSTSERVERCERTIFICATE"] = "TrustServerCertificate";
  166. _keywords ["LOAD BALANCE TIMEOUT"] = "Load Balance Timeout";
  167. _keywords ["TYPE SYSTEM VERSION"] = "Type System Version";
  168. _defaults = new Dictionary<string, object> ();
  169. _defaults.Add("Data Source", DEF_DATASOURCE);
  170. _defaults.Add("Failover Partner", DEF_FAILOVERPARTNER);
  171. _defaults.Add("AttachDbFilename", DEF_ATTACHDBFILENAME);
  172. _defaults.Add("Initial Catalog", DEF_INITIALCATALOG);
  173. _defaults.Add("Integrated Security", DEF_INTEGRATEDSECURITY);
  174. _defaults.Add("Persist Security Info", DEF_PERSISTSECURITYINFO);
  175. _defaults.Add("User ID", DEF_USERID);
  176. _defaults.Add("Password", DEF_PASSWORD);
  177. _defaults.Add("Enlist", DEF_ENLIST);
  178. _defaults.Add("Pooling", DEF_POOLING);
  179. _defaults.Add("Min Pool Size", DEF_MINPOOLSIZE);
  180. _defaults.Add("Max Pool Size", DEF_MAXPOOLSIZE);
  181. _defaults.Add("Asynchronous Processing", DEF_ASYNCHRONOUSPROCESSING);
  182. _defaults.Add("Connection Reset", DEF_CONNECTIONRESET);
  183. _defaults.Add("MultipleActiveResultSets", DEF_MULTIPLEACTIVERESULTSETS);
  184. _defaults.Add("Replication", DEF_REPLICATION);
  185. _defaults.Add("Connect Timeout", DEF_CONNECTTIMEOUT);
  186. _defaults.Add("Encrypt", DEF_ENCRYPT);
  187. _defaults.Add("TrustServerCertificate", DEF_TRUSTSERVERCERTIFICATE);
  188. _defaults.Add("Load Balance Timeout", DEF_LOADBALANCETIMEOUT);
  189. _defaults.Add("Network Library", DEF_NETWORKLIBRARY);
  190. _defaults.Add("Packet Size", DEF_PACKETSIZE);
  191. _defaults.Add("Type System Version", DEF_TYPESYSTEMVERSION);
  192. _defaults.Add("Application Name", DEF_APPLICATIONNAME);
  193. _defaults.Add("Current Language", DEF_CURRENTLANGUAGE);
  194. _defaults.Add("Workstation ID", DEF_WORKSTATIONID);
  195. _defaults.Add("User Instance", DEF_USERINSTANCE);
  196. _defaults.Add("Context Connection", DEF_CONTEXTCONNECTION);
  197. _defaults.Add("Transaction Binding", DEF_TRANSACTIONBINDING);
  198. }
  199. #endregion // Constructors
  200. #region Properties
  201. [DisplayNameAttribute ("Application Name")]
  202. [RefreshPropertiesAttribute (RefreshProperties.All)]
  203. public string ApplicationName {
  204. get { return _applicationName; }
  205. set {
  206. base ["Application Name"] = value;
  207. _applicationName = value;
  208. }
  209. }
  210. [DisplayNameAttribute ("Asynchronous Processing")]
  211. [RefreshPropertiesAttribute (RefreshProperties.All)]
  212. public bool AsynchronousProcessing {
  213. get { return _asynchronousProcessing; }
  214. set {
  215. base ["Asynchronous Processing"] = value;
  216. _asynchronousProcessing = value;
  217. }
  218. }
  219. #if NET_2_0
  220. [Editor ("System.Windows.Forms.Design.FileNameEditor, " + Consts.AssemblySystem_Design,
  221. "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  222. #else
  223. [Editor ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, " + Consts.AssemblyMicrosoft_VSDesigner,
  224. "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  225. #endif
  226. [DisplayNameAttribute ("AttachDbFilename")]
  227. [RefreshPropertiesAttribute (RefreshProperties.All)]
  228. public string AttachDBFilename {
  229. get { return _attachDBFilename; }
  230. set {
  231. base ["AttachDbFilename"] = value;
  232. _attachDBFilename = value;
  233. }
  234. }
  235. [DisplayNameAttribute ("Connection Reset")]
  236. [RefreshPropertiesAttribute (RefreshProperties.All)]
  237. public bool ConnectionReset {
  238. get { return _connectionReset; }
  239. set {
  240. base ["Connection Reset"] = value;
  241. _connectionReset = value;
  242. }
  243. }
  244. [DisplayNameAttribute ("Connect Timeout")]
  245. [RefreshPropertiesAttribute (RefreshProperties.All)]
  246. public int ConnectTimeout {
  247. get { return _connectTimeout; }
  248. set {
  249. base ["Connect Timeout"] = value;
  250. _connectTimeout = value;
  251. }
  252. }
  253. [DisplayNameAttribute ("Current Language")]
  254. [RefreshPropertiesAttribute (RefreshProperties.All)]
  255. public string CurrentLanguage {
  256. get { return _currentLanguage; }
  257. set {
  258. base ["Current Language"] = value;
  259. _currentLanguage = value;
  260. }
  261. }
  262. [DisplayNameAttribute ("Data Source")]
  263. [RefreshPropertiesAttribute (RefreshProperties.All)]
  264. #if NET_2_0
  265. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, " + Consts.AssemblySystem_Data)]
  266. #endif
  267. public string DataSource {
  268. get { return _dataSource; }
  269. set {
  270. base ["Data Source"] = value;
  271. _dataSource = value;
  272. }
  273. }
  274. [DisplayNameAttribute ("Encrypt")]
  275. [RefreshPropertiesAttribute (RefreshProperties.All)]
  276. public bool Encrypt {
  277. get { return _encrypt; }
  278. set {
  279. base ["Encrypt"] = value;
  280. _encrypt = value;
  281. }
  282. }
  283. [DisplayNameAttribute ("Enlist")]
  284. [RefreshPropertiesAttribute (RefreshProperties.All)]
  285. public bool Enlist {
  286. get { return _enlist; }
  287. set {
  288. base ["Enlist"] = value;
  289. _enlist = value;
  290. }
  291. }
  292. [DisplayNameAttribute ("Failover Partner")]
  293. [RefreshPropertiesAttribute (RefreshProperties.All)]
  294. #if NET_2_0
  295. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, " + Consts.AssemblySystem_Data)]
  296. #endif
  297. public string FailoverPartner {
  298. get { return _failoverPartner; }
  299. set {
  300. base ["Failover Partner"] = value;
  301. _failoverPartner = value;
  302. }
  303. }
  304. [DisplayNameAttribute ("Initial Catalog")]
  305. [RefreshPropertiesAttribute (RefreshProperties.All)]
  306. #if NET_2_0
  307. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+SqlInitialCatalogConverter, " + Consts.AssemblySystem_Data)]
  308. #endif
  309. public string InitialCatalog {
  310. get { return _initialCatalog; }
  311. set {
  312. base ["Initial Catalog"] = value;
  313. _initialCatalog = value;
  314. }
  315. }
  316. [DisplayNameAttribute ("Integrated Security")]
  317. [RefreshPropertiesAttribute (RefreshProperties.All)]
  318. public bool IntegratedSecurity {
  319. get { return _integratedSecurity; }
  320. set {
  321. base ["Integrated Security"] = value;
  322. _integratedSecurity = value;
  323. }
  324. }
  325. public override bool IsFixedSize {
  326. get { return true; }
  327. }
  328. public override object this [string keyword] {
  329. get {
  330. string mapped = MapKeyword (keyword);
  331. if (base.ContainsKey (mapped))
  332. return base [mapped];
  333. else
  334. return _defaults [mapped];
  335. }
  336. set {SetValue (keyword, value);}
  337. }
  338. public override ICollection Keys {
  339. get {
  340. List<string> keys = new List<string>();
  341. keys.Add("Data Source");
  342. keys.Add("Failover Partner");
  343. keys.Add("AttachDbFilename");
  344. keys.Add("Initial Catalog");
  345. keys.Add("Integrated Security");
  346. keys.Add("Persist Security Info");
  347. keys.Add("User ID");
  348. keys.Add("Password");
  349. keys.Add("Enlist");
  350. keys.Add("Pooling");
  351. keys.Add("Min Pool Size");
  352. keys.Add("Max Pool Size");
  353. keys.Add("Asynchronous Processing");
  354. keys.Add("Connection Reset");
  355. keys.Add("MultipleActiveResultSets");
  356. keys.Add("Replication");
  357. keys.Add("Connect Timeout");
  358. keys.Add("Encrypt");
  359. keys.Add("TrustServerCertificate");
  360. keys.Add("Load Balance Timeout");
  361. keys.Add("Network Library");
  362. keys.Add("Packet Size");
  363. keys.Add("Type System Version");
  364. keys.Add("Application Name");
  365. keys.Add("Current Language");
  366. keys.Add("Workstation ID");
  367. keys.Add("User Instance");
  368. keys.Add("Context Connection");
  369. keys.Add("Transaction Binding");
  370. ReadOnlyCollection<string> coll = new ReadOnlyCollection<string>(keys);
  371. return coll;
  372. }
  373. }
  374. [DisplayNameAttribute ("Load Balance Timeout")]
  375. [RefreshPropertiesAttribute (RefreshProperties.All)]
  376. public int LoadBalanceTimeout {
  377. get { return _loadBalanceTimeout; }
  378. set {
  379. base ["Load Balance Timeout"] = value;
  380. _loadBalanceTimeout = value;
  381. }
  382. }
  383. [DisplayNameAttribute ("Max Pool Size")]
  384. [RefreshPropertiesAttribute (RefreshProperties.All)]
  385. public int MaxPoolSize {
  386. get { return _maxPoolSize; }
  387. set {
  388. base ["Max Pool Size"] = value;
  389. _maxPoolSize = value;
  390. }
  391. }
  392. [DisplayNameAttribute ("Min Pool Size")]
  393. [RefreshPropertiesAttribute (RefreshProperties.All)]
  394. public int MinPoolSize {
  395. get { return _minPoolSize; }
  396. set {
  397. base ["Min Pool Size"] = value;
  398. _minPoolSize = value;
  399. }
  400. }
  401. [DisplayNameAttribute ("MultipleActiveResultSets")]
  402. [RefreshPropertiesAttribute (RefreshProperties.All)]
  403. public bool MultipleActiveResultSets {
  404. get { return _multipleActiveResultSets; }
  405. set {
  406. base ["Multiple Active Resultsets"] = value;
  407. _multipleActiveResultSets = value;
  408. }
  409. }
  410. [DisplayNameAttribute ("Network Library")]
  411. [RefreshPropertiesAttribute (RefreshProperties.All)]
  412. #if NET_2_0
  413. [TypeConverterAttribute ("System.Data.SqlClient.SqlConnectionStringBuilder+NetworkLibraryConverter, " + Consts.AssemblySystem_Data)]
  414. #endif
  415. public string NetworkLibrary {
  416. get { return _networkLibrary; }
  417. set {
  418. base ["Network Library"] = value;
  419. _networkLibrary = value;
  420. }
  421. }
  422. [DisplayNameAttribute ("Packet Size")]
  423. [RefreshPropertiesAttribute (RefreshProperties.All)]
  424. public int PacketSize {
  425. get { return _packetSize; }
  426. set {
  427. base ["Packet Size"] = value;
  428. _packetSize = value;
  429. }
  430. }
  431. [DisplayNameAttribute ("Password")]
  432. [PasswordPropertyTextAttribute (true)]
  433. [RefreshPropertiesAttribute (RefreshProperties.All)]
  434. public string Password {
  435. get { return _password; }
  436. set {
  437. base ["Password"] = value;
  438. _password = value;
  439. }
  440. }
  441. [DisplayNameAttribute ("Persist Security Info")]
  442. [RefreshPropertiesAttribute (RefreshProperties.All)]
  443. public bool PersistSecurityInfo {
  444. get { return _persistSecurityInfo; }
  445. set {
  446. base ["Persist Security Info"] = value;
  447. _persistSecurityInfo = value;
  448. }
  449. }
  450. [DisplayNameAttribute ("Pooling")]
  451. [RefreshPropertiesAttribute (RefreshProperties.All)]
  452. public bool Pooling {
  453. get { return _pooling; }
  454. set {
  455. base ["Pooling"] = value;
  456. _pooling = value;
  457. }
  458. }
  459. [DisplayNameAttribute ("Replication")]
  460. [RefreshPropertiesAttribute (RefreshProperties.All)]
  461. public bool Replication {
  462. get { return _replication; }
  463. set {
  464. base ["Replication"] = value;
  465. _replication = value;
  466. }
  467. }
  468. [DisplayNameAttribute ("User ID")]
  469. [RefreshPropertiesAttribute (RefreshProperties.All)]
  470. public string UserID {
  471. get { return _userID; }
  472. set {
  473. base ["User Id"]= value;
  474. _userID = value;
  475. }
  476. }
  477. public override ICollection Values {
  478. get {
  479. List<object> values = new List<object>();
  480. values.Add(_dataSource);
  481. values.Add(_failoverPartner);
  482. values.Add(_attachDBFilename);
  483. values.Add(_initialCatalog);
  484. values.Add(_integratedSecurity);
  485. values.Add(_persistSecurityInfo);
  486. values.Add(_userID);
  487. values.Add(_password);
  488. values.Add(_enlist);
  489. values.Add(_pooling);
  490. values.Add(_minPoolSize);
  491. values.Add(_maxPoolSize);
  492. values.Add(_asynchronousProcessing);
  493. values.Add(_connectionReset);
  494. values.Add(_multipleActiveResultSets);
  495. values.Add(_replication);
  496. values.Add(_connectTimeout);
  497. values.Add(_encrypt);
  498. values.Add(_trustServerCertificate);
  499. values.Add(_loadBalanceTimeout);
  500. values.Add(_networkLibrary);
  501. values.Add(_packetSize);
  502. values.Add(_typeSystemVersion);
  503. values.Add(_applicationName);
  504. values.Add(_currentLanguage);
  505. values.Add(_workstationID);
  506. values.Add(_userInstance);
  507. values.Add(_contextConnection);
  508. values.Add(_transactionBinding);
  509. ReadOnlyCollection<object> coll = new ReadOnlyCollection<object>(values);
  510. return coll;
  511. }
  512. }
  513. [DisplayNameAttribute ("Workstation ID")]
  514. [RefreshPropertiesAttribute (RefreshProperties.All)]
  515. public string WorkstationID {
  516. get { return _workstationID; }
  517. set {
  518. base ["Workstation Id"] = value;
  519. _workstationID = value;
  520. }
  521. }
  522. [DisplayNameAttribute ("TrustServerCertificate")]
  523. [RefreshProperties (RefreshProperties.All)]
  524. public bool TrustServerCertificate {
  525. get { return _trustServerCertificate; }
  526. set {
  527. base ["Trust Server Certificate"] = value;
  528. _trustServerCertificate = value;
  529. }
  530. }
  531. [DisplayNameAttribute ("Type System Version")]
  532. [RefreshProperties (RefreshProperties.All)]
  533. public string TypeSystemVersion {
  534. get { return _typeSystemVersion; }
  535. set {
  536. base ["Type System Version"] = value;
  537. _typeSystemVersion = value;
  538. }
  539. }
  540. [DisplayNameAttribute ("User Instance")]
  541. [RefreshProperties (RefreshProperties.All)]
  542. public bool UserInstance {
  543. get { return _userInstance; }
  544. set {
  545. base ["User Instance"] = value;
  546. _userInstance = value;
  547. }
  548. }
  549. [RefreshPropertiesAttribute (RefreshProperties.All)]
  550. [DisplayNameAttribute ("Context Connection")]
  551. public bool ContextConnection {
  552. get { return _contextConnection; }
  553. set {
  554. base ["Context Connection"] = value;
  555. _contextConnection = value;
  556. }
  557. }
  558. #endregion // Properties
  559. #region Methods
  560. private void Init ()
  561. {
  562. _applicationName = DEF_APPLICATIONNAME;
  563. _asynchronousProcessing = DEF_ASYNCHRONOUSPROCESSING;
  564. _attachDBFilename = DEF_ATTACHDBFILENAME;
  565. _connectionReset = DEF_CONNECTIONRESET;
  566. _connectTimeout = DEF_CONNECTTIMEOUT;
  567. _currentLanguage = DEF_CURRENTLANGUAGE;
  568. _dataSource = DEF_DATASOURCE;
  569. _encrypt = DEF_ENCRYPT;
  570. _enlist = DEF_ENLIST;
  571. _failoverPartner = DEF_FAILOVERPARTNER;
  572. _initialCatalog = DEF_INITIALCATALOG;
  573. _integratedSecurity = DEF_INTEGRATEDSECURITY;
  574. _loadBalanceTimeout = DEF_LOADBALANCETIMEOUT;
  575. _maxPoolSize = DEF_MAXPOOLSIZE;
  576. _minPoolSize = DEF_MINPOOLSIZE;
  577. _multipleActiveResultSets= DEF_MULTIPLEACTIVERESULTSETS;
  578. _networkLibrary = DEF_NETWORKLIBRARY;
  579. _packetSize = DEF_PACKETSIZE;
  580. _password = DEF_PASSWORD;
  581. _persistSecurityInfo = DEF_PERSISTSECURITYINFO;
  582. _pooling = DEF_POOLING;
  583. _replication = DEF_REPLICATION;
  584. _userID = DEF_USERID;
  585. _workstationID = DEF_WORKSTATIONID;
  586. _trustServerCertificate = DEF_TRUSTSERVERCERTIFICATE;
  587. _typeSystemVersion = DEF_TYPESYSTEMVERSION;
  588. _userInstance = DEF_USERINSTANCE;
  589. _contextConnection = DEF_CONTEXTCONNECTION;
  590. _transactionBinding = DEF_TRANSACTIONBINDING;
  591. }
  592. public override void Clear ()
  593. {
  594. base.Clear ();
  595. Init ();
  596. }
  597. public override bool ContainsKey (string keyword)
  598. {
  599. keyword = keyword.ToUpper ().Trim ();
  600. if (_keywords.ContainsKey (keyword))
  601. return base.ContainsKey (_keywords [keyword]);
  602. return false;
  603. }
  604. public override bool Remove (string keyword)
  605. {
  606. if (!ContainsKey (keyword))
  607. return false;
  608. this [keyword] = null;
  609. return true;
  610. }
  611. [MonoNotSupported ("")] // Note that base.ShouldSerialize() is called but not implemented
  612. public override bool ShouldSerialize (string keyword)
  613. {
  614. if (!ContainsKey (keyword))
  615. return false;
  616. keyword = keyword.ToUpper ().Trim ();
  617. // Assuming passwords cannot be serialized.
  618. if (_keywords [keyword] == "Password")
  619. return false;
  620. return base.ShouldSerialize (_keywords [keyword]);
  621. }
  622. public override bool TryGetValue (string keyword, out object value)
  623. {
  624. if (! ContainsKey (keyword)) {
  625. value = String.Empty;
  626. return false;
  627. }
  628. return base.TryGetValue (_keywords [keyword.ToUpper ().Trim ()], out value);
  629. }
  630. #endregion // Methods
  631. #region Private Methods
  632. private string MapKeyword (string keyword)
  633. {
  634. keyword = keyword.ToUpper ().Trim ();
  635. if (! _keywords.ContainsKey (keyword))
  636. throw new ArgumentException("Keyword not supported :" + keyword);
  637. return _keywords [keyword];
  638. }
  639. private void SetValue (string key, object value)
  640. {
  641. if (key == null)
  642. throw new ArgumentNullException ("key cannot be null!");
  643. string mappedKey = MapKeyword (key);
  644. switch (mappedKey.ToUpper ().Trim ()) {
  645. case "APPLICATION NAME" :
  646. if (value == null) {
  647. _applicationName = DEF_APPLICATIONNAME;
  648. base.Remove (mappedKey);
  649. } else
  650. this.ApplicationName = value.ToString ();
  651. break;
  652. case "ATTACHDBFILENAME" :
  653. throw new NotImplementedException ("Attachable database support is " +
  654. "not implemented.");
  655. case "CONNECT TIMEOUT" :
  656. if (value == null) {
  657. _connectTimeout = DEF_CONNECTTIMEOUT;
  658. base.Remove (mappedKey);
  659. } else
  660. this.ConnectTimeout = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  661. break;
  662. case "CONNECTION LIFETIME" :
  663. break;
  664. case "CONNECTION RESET" :
  665. if (value == null) {
  666. _connectionReset = DEF_CONNECTIONRESET;
  667. base.Remove (mappedKey);
  668. } else
  669. this.ConnectionReset = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  670. break;
  671. case "CURRENT LANGUAGE" :
  672. if (value == null) {
  673. _currentLanguage = DEF_CURRENTLANGUAGE;
  674. base.Remove (mappedKey);
  675. } else
  676. this.CurrentLanguage = value.ToString ();
  677. break;
  678. case "CONTEXT CONNECTION" :
  679. if (value == null) {
  680. _contextConnection = DEF_CONTEXTCONNECTION;
  681. base.Remove (mappedKey);
  682. } else
  683. this.ContextConnection = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  684. break;
  685. case "DATA SOURCE" :
  686. if (value == null) {
  687. _dataSource = DEF_DATASOURCE;
  688. base.Remove (mappedKey);
  689. } else
  690. this.DataSource = value.ToString ();
  691. break;
  692. case "ENCRYPT":
  693. if (value == null) {
  694. _encrypt = DEF_ENCRYPT;
  695. base.Remove (mappedKey);
  696. }else if (DbConnectionStringBuilderHelper.ConvertToBoolean(value))
  697. throw new NotImplementedException("SSL encryption for"
  698. + " data sent between client and server is not"
  699. + " implemented.");
  700. break;
  701. case "ENLIST" :
  702. if (value == null) {
  703. _enlist = DEF_ENLIST;
  704. base.Remove (mappedKey);
  705. } else if ( ! DbConnectionStringBuilderHelper.ConvertToBoolean(value))
  706. throw new NotImplementedException("Disabling the automatic"
  707. + " enlistment of connections in the thread's current"
  708. + " transaction context is not implemented.");
  709. break;
  710. case "INITIAL CATALOG" :
  711. if (value == null) {
  712. _initialCatalog = DEF_INITIALCATALOG;
  713. base.Remove (mappedKey);
  714. } else
  715. this.InitialCatalog = value.ToString ();
  716. break;
  717. case "INTEGRATED SECURITY" :
  718. if (value == null) {
  719. _integratedSecurity = DEF_INTEGRATEDSECURITY;
  720. base.Remove (mappedKey);
  721. } else
  722. this.IntegratedSecurity = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  723. break;
  724. case "MAX POOL SIZE" :
  725. if (value == null) {
  726. _maxPoolSize = DEF_MAXPOOLSIZE;
  727. base.Remove (mappedKey);
  728. } else
  729. this.MaxPoolSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  730. break;
  731. case "MIN POOL SIZE" :
  732. if (value == null) {
  733. _minPoolSize = DEF_MINPOOLSIZE;
  734. base.Remove (mappedKey);
  735. } else
  736. this.MinPoolSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  737. break;
  738. case "MULTIPLEACTIVERESULTSETS":
  739. if (value == null) {
  740. _multipleActiveResultSets = DEF_MULTIPLEACTIVERESULTSETS;
  741. base.Remove (mappedKey);
  742. } else if ( DbConnectionStringBuilderHelper.ConvertToBoolean (value))
  743. throw new NotImplementedException ("MARS is not yet implemented!");
  744. break;
  745. case "ASYNCHRONOUS PROCESSING" :
  746. if (value == null) {
  747. _asynchronousProcessing = DEF_ASYNCHRONOUSPROCESSING;
  748. base.Remove (mappedKey);
  749. } else
  750. this.AsynchronousProcessing = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  751. break;
  752. case "NETWORK LIBRARY" :
  753. if (value == null) {
  754. _networkLibrary = DEF_NETWORKLIBRARY;
  755. base.Remove (mappedKey);
  756. } else {
  757. if (!value.ToString ().ToUpper ().Equals ("DBMSSOCN"))
  758. throw new ArgumentException ("Unsupported network library.");
  759. this.NetworkLibrary = value.ToString ().ToLower ();
  760. }
  761. break;
  762. case "LOAD BALANCE TIMEOUT":
  763. // TODO: what is this?
  764. break;
  765. case "PACKET SIZE" :
  766. if (value == null) {
  767. _packetSize = DEF_PACKETSIZE;
  768. base.Remove (mappedKey);
  769. } else
  770. this.PacketSize = DbConnectionStringBuilderHelper.ConvertToInt32 (value);
  771. break;
  772. case "PASSWORD" :
  773. if (value == null) {
  774. _password = DEF_PASSWORD;
  775. base.Remove (mappedKey);
  776. } else
  777. this.Password = value.ToString ();
  778. break;
  779. case "PERSIST SECURITY INFO" :
  780. if (value == null) {
  781. _persistSecurityInfo = DEF_PERSISTSECURITYINFO;
  782. base.Remove (mappedKey);
  783. } else if (DbConnectionStringBuilderHelper.ConvertToBoolean (value))
  784. throw new NotImplementedException ("Persisting security info" +
  785. " is not yet implemented");
  786. break;
  787. case "POOLING" :
  788. if (value == null) {
  789. _pooling = DEF_POOLING;
  790. base.Remove (mappedKey);
  791. } else
  792. this.Pooling = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  793. break;
  794. case "USER ID" :
  795. if (value == null) {
  796. _userID = DEF_USERID;
  797. base.Remove (mappedKey);
  798. } else
  799. this.UserID = value.ToString ();
  800. break;
  801. case "USER INSTANCE" :
  802. if (value == null) {
  803. _userInstance = DEF_USERINSTANCE;
  804. base.Remove (mappedKey);
  805. } else
  806. this.UserInstance = DbConnectionStringBuilderHelper.ConvertToBoolean (value);
  807. break;
  808. case "WORKSTATION ID" :
  809. if (value == null) {
  810. _workstationID = DEF_WORKSTATIONID;
  811. base.Remove (mappedKey);
  812. } else
  813. this.WorkstationID = value.ToString ();
  814. break;
  815. case "TRANSACTION BINDING":
  816. // TODO: what is this?
  817. break;
  818. default :
  819. throw new ArgumentException("Keyword not supported :" + key);
  820. }
  821. }
  822. #endregion // Private Methods
  823. }
  824. }
  825. #endif // NET_2_0