**** Merged from MCS ****
[mono-project.git] / mcs / class / ByteFX.Data / mysqlclient / docs / MySqlConnection.xml
blob4ab4da1a0cc34fc9fd4363cdc5e1b559906fcc02
1 <MyDocs>\r
2 <MyMembers name="Class">\r
3 <remarks>\r
4         <para>\r
5                 A <b>MySqlConnection</b> object represents a session to a MySQL Server \r
6                 data source.  When you create an instance of <B>MySqlConnection</B>, all \r
7                 properties are set to their initial values. For a list of these values, see the \r
8                 <B>MySqlConnection</B> constructor.\r
9         </para>\r
11         <para>\r
12                 If the <B>MySqlConnection</B> goes out of scope, it is not closed. Therefore, \r
13                 you must explicitly close the connection by calling <see cref="MySqlConnection.Close"/> \r
14                 or <see cref="MySqlConnection.Dispose"/>.\r
15         </para>\r
17 </remarks>\r
19 <example>\r
20         The following example creates a <see cref="MySqlCommand"/> and \r
21         a <B>MySqlConnection</B>. The <B>MySqlConnection</B> is opened and set as the  \r
22         <see cref="MySqlCommand.Connection"/> for the <B>MySqlCommand</B>. The example then calls  \r
23         <see cref="MySqlCommand.ExecuteNonQuery"/>, and closes the connection. To accomplish this, the <B>ExecuteNonQuery</B> is \r
24         passed a connection string and a query string that is a SQL INSERT \r
25         statement.\r
26         <code lang="Visual Basic">\r
27         <c>\r
28 Public Sub InsertRow(myConnectionString As String)\r
29         ' If the connection string is null, use a default.\r
30         If myConnectionString = "" Then\r
31                 myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass"\r
32         End If\r
33         Dim myConnection As New MySqlConnection(myConnectionString)\r
34         Dim myInsertQuery As String = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)"\r
35         Dim myCommand As New MySqlCommand(myInsertQuery)\r
36         myCommand.Connection = myConnection\r
37         myConnection.Open()\r
38         myCommand.ExecuteNonQuery()\r
39         myCommand.Connection.Close()\r
40 End Sub\r
41 </c> \r
42         </code>\r
43         <code lang="C#">\r
44 <c>\r
45 public void InsertRow(string myConnectionString) \r
46 {\r
47         // If the connection string is null, use a default.\r
48         if(myConnectionString == "") \r
49         {\r
50                 myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass";\r
51         }\r
52         MySqlConnection myConnection = new MySqlConnection(myConnectionString);\r
53         string myInsertQuery = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)";\r
54         MySqlCommand myCommand = new MySqlCommand(myInsertQuery);\r
55         myCommand.Connection = myConnection;\r
56         myConnection.Open();\r
57         myCommand.ExecuteNonQuery();\r
58         myCommand.Connection.Close();\r
59 }\r
60 </c>\r
61         </code>\r
62 </example>\r
65 </MyMembers>\r
67 <MyMembers name="ConnectionTimeout">\r
68         <exception cref="System.ArgumentException">The value set is less than 0.</exception>\r
69         <remarks>\r
70                 A value of 0 indicates no limit, and should be avoided in a \r
71                 <see cref="MySqlConnection.ConnectionString"/> because an attempt to connect \r
72                 will wait indefinitely.\r
73         </remarks>\r
74         <example>\r
75                 The following example creates a MySqlConnection\r
76                 and sets some of its properties in the connection string.\r
77                 <code lang="Visual Basic">\r
78 Public Sub CreateSqlConnection()\r
79         Dim myConnection As New MySqlConnection()\r
80         myConnection.ConnectionString = "Persist Security Info=False;Username=user;Password=pass;database=test1;server=localhost;Connect Timeout=30"\r
81         myConnection.Open()\r
82 End Sub\r
83 </code>\r
84 <code lang="C#">\r
85 public void CreateSqlConnection() \r
86 {\r
87         MySqlConnection myConnection = new MySqlConnection();\r
88         myConnection.ConnectionString = "Persist Security Info=False;Username=user;Password=pass;database=test1;server=localhost;Connect Timeout=30";\r
89         myConnection.Open();\r
90 }\r
91 </code>                         \r
92         </example>\r
93 </MyMembers>\r
96 <MyMembers name="ConnectionString">\r
97         <remarks>\r
98         <para>The <B>ConnectionString</B> returned may not be exactly like what was originally\r
99         set but will be indentical in terms of keyword/value pairs.  Security information\r
100         will not be included unless the Persist Security Info value is set to true. \r
101         </para>\r
102         <para>You can use the <B>ConnectionString</B> property to connect to a database. \r
103         The following example illustrates a typical connection string.</para>\r
104         <c>"Persist Security Info=False;database=MyDB;server=MySqlServer;user id=myUser;Password=myPass"</c>\r
105         <para>The <B>ConnectionString</B> property can be set only when the connection is \r
106         closed. Many of the connection string values have corresponding read-only \r
107         properties. When the connection string is set, all of these properties are \r
108         updated, except when an error is detected. In this case, none of the properties \r
109         are updated. <see cref="MySqlConnection"/> properties return only those settings contained in the \r
110         <B>ConnectionString</B>.</para>\r
111         <para>To connect to a local machine, specify "localhost" for the server. If you do not \r
112         specify a server, localhost is assumed.</para>\r
113         <para>Resetting the <B>ConnectionString</B> on a closed connection resets all \r
114         connection string values (and related properties) including the password. For \r
115         example, if you set a connection string that includes "Database= MyDb", and \r
116         then reset the connection string to "Data Source=myserver;User Id=myUser;Password=myPass", \r
117         the <see cref="MySqlConnection.Database"/> property is no longer set to MyDb.</para>\r
118         <para>The connection string is parsed immediately after being set. If errors in \r
119         syntax are found when parsing, a runtime exception, such as <see cref="ArgumentException"/>, \r
120         is generated. Other errors can be found only when an attempt is made to open the \r
121         connection.</para>\r
122         <para>The basic format of a connection string consists of a series of keyword/value \r
123         pairs separated by semicolons. The equal sign (=) connects each keyword and its \r
124         value. To include values that contain a semicolon, single-quote character, or \r
125         double-quote character, the value must be enclosed in double quotes. If the \r
126         value contains both a semicolon and a double-quote character, the value can be \r
127         enclosed in single quotes. The single quote is also useful if the value begins \r
128         with a double-quote character. Conversely, the double quote can be used if the \r
129         value begins with a single quote. If the value contains both single-quote and \r
130         double-quote characters, the quote character used to enclose the value must be \r
131         doubled each time it occurs within the value.</para>\r
132         <para>To include preceding or trailing spaces in the string value, the value must \r
133         be enclosed in either single quotes or double quotes. Any leading or trailing \r
134         spaces around integer, Boolean, or enumerated values are ignored, even if \r
135         enclosed in quotes. However, spaces within a string literal keyword or value are \r
136         preserved. Using .NET Framework version 1.1, single or double quotes may be used \r
137         within a connection string without using delimiters (for example, Data Source= \r
138         my'Server or Data Source= my"Server), unless a quote character is the first or \r
139         last character in the value.</para>\r
140         <para>To include an equal sign (=) in a keyword or value, it must be preceded by \r
141         another equal sign. For example, in the hypothetical connection string</para>\r
142         <c>"key==word=value"</c>\r
143         <para></para>\r
144         <para>the keyword is "key=word" and the value is "value".</para>\r
145         <para>If a specific keyword in a keyword= value pair occurs multiple times in a \r
146         connection string, the last occurrence listed is used in the value set.</para>\r
147         <para>Keywords are not case sensitive.</para>\r
148         <para>The following table lists the valid names for keyword values within the \r
149         <B>ConnectionString</B>.</para>\r
150         <div class="tablediv"><table class="dtTABLE" cellspacing="0"><tr valign="top">\r
151                 <th width="33%">Name</th>\r
152                 <th width="33%">Default</th>\r
153                 <th width="33%">Description</th>\r
154                 </tr>\r
155                 <tr>\r
156                         <td>Connect Timeout<para>  -or-  </para>Connection Timeout</td>\r
157                         <td>15</td>\r
158                         <td>The length of time (in seconds) to wait for a connection to the server before \r
159 terminating the attempt and generating an error.</td>\r
160                 </tr>\r
161                 <tr>\r
162                         <td>\r
163                                 Host<para>  -or-  </para>Server<para>  -or-  </para>Data Source<para>  -or-  </para>\r
164                                 DataSource<para>  -or-  </para>Address<para>  -or-  </para>Addr<para>  -or-  </para>\r
165                                 Network Address\r
166                         </td>\r
167                         <td>localhost</td>\r
168                         <td><para>The name or network address of the instance of MySQL to which to connect.  Multiple hosts can be\r
169                         specified separated by &amp;.  This can be useful where multiple MySQL servers are configured for replication\r
170                         and you are not concerned about the precise server you are connecting to.  No attempt is made by the provider to\r
171                         synchronize writes to the database so care should be taken when using this option.\r
172                         </para>\r
173                         <para>\r
174                                 In Unix environment with Mono, this can be a fully qualified path to MySQL socket filename. With this configuration, the Unix socket will be used instead of TCP/IP socket.\r
175                                 Currently only a single socket name can be given so accessing MySQL in a replicated environment using Unix sockets is not currently supported.\r
176                         </para>\r
177                         </td>\r
178                 </tr>\r
179                 <tr>\r
180                         <td>Port</td>\r
181                         <td>3306</td>\r
182                         <td>The port MySQL is using to listen for connections.  Specify -1 for this value to use a \r
183                                 named pipe connection (Windows only). This value is ignored if Unix socket is used.</td>\r
184                 </tr>\r
185                 <tr>\r
186                         <td>Encrypt</td>\r
187                         <td>false</td>\r
188                         <td>When <B>true</B>, SSL encryption is used for all data sent between the \r
189 client and server if the server has a certificate installed. Recognized values \r
190 are <B>true</B>, <B>false</B>, <B>yes</B>, and <B>no</B>.<para><b>Note</b>  This parameter currently has no\r
191 effect.</para></td>\r
192                 </tr>\r
193                 <tr>\r
194                         <td>Initial Catalog<para>  -or-  </para>Database</td>\r
195                         <td></td>\r
196                         <td>The name of the database to use intially</td>\r
197                 </tr>\r
198                 <tr>\r
199                         <td>Password<para>  -or-  </para>pwd</td>\r
200                         <td></td>\r
201                         <td>The password for the MySQL account being used.</td>\r
202                 </tr>\r
203                 <tr>\r
204                         <td>Persist Security Info</td>\r
205                         <td>false</td>\r
206                         <td>When set to <B>false</B> or <B>no</B> (strongly recommended), security-sensitive \r
207 information, such as the password, is not returned as part of the connection if \r
208 the connection is open or has ever been in an open state. Resetting the \r
209 connection string resets all connection string values including the password. \r
210 Recognized values are <B>true</B>, <B>false</B>, <B>yes</B>, and <B>no</B>.</td>\r
211                 </tr>\r
212                 <tr>\r
213                         <td>User Id<para>  -or-  </para>Username<para>  -or-  </para>Uid<para>  -or-  </para>User name</td>\r
214                         <td></td>\r
215                         <td>The MySQL login account being used.</td>\r
216                 </tr>\r
217                 </table>\r
218                 </div>\r
219         <para>\r
220         The following table lists the valid names for connection pooling values within \r
221 the <B>ConnectionString</B>. For more information about connection pooling, see \r
222 Connection Pooling for the ByteFX Data Provider for MySQL.</para>\r
223         <div class="tablediv"><table class="dtTABLE" cellspacing="0"><tr valign="top">\r
224                 <th width="33%">Name</th>\r
225                 <th width="33%">Default</th>\r
226                 <th width="33%">Description</th>\r
227                 </tr>\r
228                 <tr>\r
229                         <td>Connection Lifetime</td>\r
230                         <td>0</td>\r
231                         <td>When a connection is returned to the pool, its creation time is compared with \r
232 the current time, and the connection is destroyed if that time span (in seconds) \r
233 exceeds the value specified by <B>Connection Lifetime</B>. This is useful in \r
234 clustered configurations to force load balancing between a running server and a \r
235 server just brought online. \r
236 <para>A value of zero (0) causes pooled connections to have the maximum connection \r
237 timeout.</para></td>\r
238                 </tr>\r
239                 <tr>\r
240                         <td>Max Pool Size</td>\r
241                         <td>100</td>\r
242                         <td>The maximum number of connections allowed in the pool.</td>\r
243                 </tr>\r
244                 <tr>\r
245                         <td>Min Pool Size</td>\r
246                         <td>0</td>\r
247                         <td>The minimum number of connections allowed in the pool.</td>\r
248                 </tr>\r
249                 <tr>\r
250                         <td>Pooling</td>\r
251                         <td>true</td>\r
252                         <td>When <B>true</B>, the <B>MySqlConnection</B> object is drawn from the appropriate \r
253 pool, or if necessary, is created and added to the appropriate pool. Recognized \r
254 values are <B>true</B>, <B>false</B>, <B>yes</B>, and <B>no</B>.</td>\r
255                 </tr>\r
256                 <tr>\r
257                         <td>Use Pipe<para>  -or-  </para>Pipe</td>\r
258                         <td></td>\r
259                         <td>When set to the name of a named pipe, the <B>MySqlConnection</B> will attempt to connect to MySQL\r
260                         on that named pipe.<br/><br/>This settings only applies to the Windows platform.</td>\r
261                 </tr>\r
262         </table></div>\r
263 <para>When setting keyword or connection pooling values that require a Boolean \r
264 value, you can use 'yes' instead of 'true', and 'no' instead of 'false'.</para>\r
265 <para><B>Note</B>  The ByteFX Data Provider for MySQL uses the native socket protocol to \r
266 communicate with MySQL.  Therefore, it does not support the use of an ODBC data source name (DSN) when \r
267 connecting to MySQL because it does not add an ODBC layer.</para>\r
268 <para><B>CAUTION</B>  In this release, the application should use caution when constructing a \r
269 connection string based on user input (for example when retrieving user ID and password information from a \r
270 dialog box, and appending it to the connection string). The application should \r
271 ensure that a user cannot embed extra connection string parameters in these \r
272 values (for example, entering a password as "validpassword;database=somedb" in \r
273 an attempt to attach to a different database).</para>\r
274         </remarks>\r
275         <example>\r
276         The following example creates a <see cref="MySqlConnection"/> and sets some of its properties\r
277         <code lang="Visual Basic">\r
278         Public Sub CreateConnection()\r
279                 Dim myConnection As New MySqlConnection()\r
280                 myConnection.ConnectionString = "Persist Security Info=False;database=myDB;server=myHost;Connect Timeout=30;user id=myUser; pwd=myPass"\r
281                 myConnection.Open()\r
282         End Sub 'CreateConnection\r
283         </code>\r
284         <code lang="C#">\r
285         public void CreateConnection() \r
286         {\r
287                 MySqlConnection myConnection = new MySqlConnection();\r
288                 myConnection.ConnectionString = "Persist Security Info=False;database=myDB;server=myHost;Connect Timeout=30;user id=myUser; pwd=myPass";\r
289                 myConnection.Open();\r
290         }\r
291         </code>\r
292 </example>\r
293         <example>\r
294                 The following example creates a <see cref="MySqlConnection"/> in Unix environment with Mono installed. MySQL socket filename used in this example is "/var/lib/mysql/mysql.sock". The actual filename depends on your MySQL configuration.\r
295         <code lang="Visual Basic">\r
296         Public Sub CreateConnection()\r
297                 Dim myConnection As New MySqlConnection()\r
298                 myConnection.ConnectionString = "database=myDB;server=/var/lib/mysql/mysql.sock;user id=myUser; pwd=myPass"\r
299                 myConnection.Open()\r
300         End Sub 'CreateConnection\r
301         </code>\r
302         <code lang="C#">\r
303         public void CreateConnection() \r
304         {\r
305                 MySqlConnection myConnection = new MySqlConnection();\r
306                 myConnection.ConnectionString = "database=myDB;server=/var/lib/mysql/mysql.sock;user id=myUser; pwd=myPass";\r
307                 myConnection.Open();\r
308         }\r
309         </code>\r
310         </example>\r
311 </MyMembers>\r
312 </MyDocs>\r