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