Connection.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // ByteFX.Data data access components for .Net
  2. // Copyright (C) 2002-2003 ByteFX, Inc.
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using System;
  18. using System.ComponentModel;
  19. using System.Collections.Specialized;
  20. using System.Data;
  21. namespace ByteFX.Data.Common
  22. {
  23. /// <summary>
  24. /// Summary description for Connection.
  25. /// </summary>
  26. [ToolboxItem(false)]
  27. [System.ComponentModel.DesignerCategory("Code")]
  28. public class Connection : Component
  29. {
  30. internal ConnectionString connString;
  31. internal ConnectionState state;
  32. internal IDataReader reader = null;
  33. public Connection(System.ComponentModel.IContainer container)
  34. {
  35. /// <summary>
  36. /// Required for Windows.Forms Class Composition Designer support
  37. /// </summary>
  38. container.Add(this);
  39. Init();
  40. }
  41. public Connection()
  42. {
  43. Init();
  44. }
  45. protected void Init()
  46. {
  47. state = ConnectionState.Closed;
  48. }
  49. [Browsable(true)]
  50. public string DataSource
  51. {
  52. get
  53. {
  54. String s = connString["data source"];
  55. if (s == null || s.Length == 0)
  56. return "localhost";
  57. return s;
  58. }
  59. }
  60. [Browsable(false)]
  61. public string User
  62. {
  63. get
  64. {
  65. string s = connString["user id"];
  66. if (s == null)
  67. s = "";
  68. return s;
  69. }
  70. }
  71. [Browsable(false)]
  72. public string Password
  73. {
  74. get
  75. {
  76. string pwd = connString["password"];
  77. if (pwd == null)
  78. pwd = "";
  79. return pwd;
  80. }
  81. }
  82. [Browsable(true)]
  83. public int ConnectionTimeout
  84. {
  85. get
  86. {
  87. // Returns the connection time-out value set in the connection
  88. // string. Zero indicates an indefinite time-out period.
  89. if (connString == null)
  90. return 30;
  91. return connString.GetIntOption("connection timeout", 30);
  92. }
  93. }
  94. [Browsable(true)]
  95. public string Database
  96. {
  97. get
  98. {
  99. // Returns an initial database as set in the connection string.
  100. // An empty string indicates not set - do not return a null reference.
  101. return connString["database"];
  102. }
  103. }
  104. [Browsable(false)]
  105. public ConnectionState State
  106. {
  107. get { return state; }
  108. }
  109. internal IDataReader Reader
  110. {
  111. get { return reader; }
  112. set { reader = value; }
  113. }
  114. }
  115. }