2004-01-04 Daniel Morgan <danielmorgan@verizon.net>
[mono.git] / doc / ado-net
1 * ADO.NET
2
3 ** Data Access in Mono
4
5 <ul>
6         <li>Today, our goal is to be compatible with .NET 1.0 and .NET 1.1.  We also would like
7    to extend data access beyond what is included with .NET 1.0 and .NET 1.1,
8    such as, including access to more databases, such as, PostgreSQL and MySQL,
9    but also provide classes that help in creating data source-agnostic code, such as, Mono.Data.ProviderFactory.</li>
10    <li>In the future, we would like to be compatible with .NET 1.2. This
11    would include features like:
12         <ul> 
13                 <li><a href="http://longhorn.msdn.microsoft.com/lhsdk/ndp/daconworkingwithobjectspacesarchitecture.aspx">ObjectSpaces</a></li>
14                 <li>provide support for hosting Mono languages (C-Sharp, MonoBASIC, etc...)
15             within a DBMS engine, such as, MySQL or PostgreSQL.</li>
16                 <li>implement .net 1.2 classes, such as, those found in System.Data.ProviderBase</li>
17                 <li>other stuff which can be brought up on the mono-list</li>
18         </ul></li>
19 </ul>
20
21 ** Bugs and Feature Requests
22
23 <ul>
24
25         <li>Bugs with Mono or any data provider in Mono should be reported 
26             in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>.  If you
27             do not have a Bugzilla user account, it is free 
28             and easy to create 
29             one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
30         
31         <li>Any requests for new features or missing functionality
32             can entered as a bug in Bugzilla too</li>
33
34 </ul>
35         
36 ** ADO.NET Data Providers
37         
38 <p>Mono has many ADO.NET Data Providers to get you connected:
39                         
40 <ul>
41         <li><a href="http://www.go-mono.com/ibmdb2.html">IBM DB2 Universal Database</a></li>
42         <li><a href="http://www.go-mono.com/mysql.html">MySQL</a></li>
43         <li><a href="http://www.go-mono.com/odbc.html">ODBC</a></li>
44         <li><a href="http://www.go-mono.com/oracle.html">Oracle</a></li>
45         <li><a href="http://www.go-mono.com/oledb.html">OLE DB</a></li>
46         <li><a href="http://www.go-mono.com/postgresql.html">PostgreSQL</a></li>
47         <li><a href="http://www.go-mono.com/sqlclient.html">Microsoft SQL Server</a></li>
48         <li><a href="http://www.go-mono.com/sqlite.html">SQL Lite</a></li>
49         <li><a href="http://www.go-mono.com/sybase.html">Sybase</a></li>
50         <li><a href="http://www.go-mono.com/tdsclient.html">TDS Generic</a></li>
51 </ul>
52
53 <p>Providers which we do not have, but we would like to have.  Currently,
54         some of these databases are supported via the ODBC or OLE DB providers.
55
56 <ul>
57         <li><a href="http://msdn.microsoft.com/library/en-us/dnsql2k/html/sqlxml_intromanagedclasses.asp?frame=true">Managed Classes for SqlXml</a> which is
58                 a .NET data provider for retrieving XML data from a Microsoft SQL Server 2000 database.  The System.Data.SqlClient provider
59                 in Mono can be used as a starting point at mcs/class/System.Data/System.Data.SqlClient.</li>
60         <li><a href="http://www.hughes.com.au/">miniSQL</a></li>
61         <li><a href="http://www.sleepycat.com/">BerkeleyDB (Sleepycat)</a></li>
62         <li><a href="http://www.sapdb.org/">SapDB</a></li>
63         <li><a href="http://www-3.ibm.com/software/data/informix/">Informix</a></li>    
64         <li><a href="http://msdn.microsoft.com/vfoxpro/">Foxpro</a></li>        
65         <li>Microsoft Access - could be done by creating C# bindings to <a href="http://mdbtools.sourceforge.net">MDB Tools</a></li>
66         <li>dbase or xbase type database files</li>
67         <li>Others are welcome</li>
68 </ul>
69
70 <p>External Projects that have created ADO.NET Providers that work on Mono:
71
72 <ul>
73
74         <li><a href="http://www.go-mono.com/firebird.html">Firebird Interbase</a></li> is a
75            Firebird SQL Managed data provider. It can be used with Interbase databases too.  It
76            is written in 100%C# and does not require a client library. Works on .NET and Mono.</a>
77         <li><a href="http://gborg.postgresql.org/project/npgsql/projdisplay.php">Npgsql</a> is a 
78            PostgreSQL Managed data provider written 
79            in 100% C#, does not require a client library, and works on .NET and Mono</li>
80         <li><a href="http://sourceforge.net/projects/mysqlnet/">MySQLNet</a> is a 
81            MySQL Managed data provider written in 100% C#, does not
82            require a client library, and works on .NET and Mono</li>
83 </ul>
84
85 ** Tools
86
87 <p>Some tools that can be used for ADO.NET and other technologies (ASP.NET, XML, etc).
88
89 <ul>    
90                 <li><p><b>SQL# command line query tool</b> is a command-line tool to
91                     enter and execute SQL statements or 
92                     execute a batch of SQL commands from a file.
93                   <p>It can
94                   be used to test connection strings, connect to various ADO.NET
95                   providers, save output to text, html, or xml.
96                   <p>The SQL# CLI is distributed with the
97                   Mono runtime and class libraries as an executable assembly sqlsharp.exe.
98                   <p>The source to SQL# CLI can be found in the mcs source at
99                   mcs/tools/SqlSharp/SqlSharpCli.cs
100                   </li>
101                   
102                 <li><p><b>SQL# For GTK#</b> - is a graphical SQL database query tool</b> allows a user
103                   to enter SQL commands in a top panel which is a text editor.
104                   <p>It has a toolbar and menu for various tasks, such as, executing
105                   SQL commands one-at-a-time or in a batch.  The results would appear
106                   in a bottom panel in a grid or could be saved to a file (xml, html, csv).
107                   <p>Also, the bottom panel would allow logging of SQL command executed.
108                   Here is a screenshot of <a href="http://go-mono.com/images/sqlsharp.png">SQL# For GTK#</a> which
109                   provides a GUI interface using the <a href="http://gtk-sharp.sourceforge.net">Gtk#</a> toolkit.
110                   <p>SQL# For GTK# can be found in mono cvs as sqlsharpgtk.</li>  
111 </ul>
112
113 <p>Tools we would like to have, but they have not been created yet:
114
115 <ul>
116                 <li>Mono has an <b>XML Schema Definition tool</b> (xsd.exe).</b>
117                                         
118                         <ul>
119                                 <li>This tool
120                                         would works like the xsd.exe tool included with 
121                                         the .NET Framework.  The Xsd.exe tool has the\r
122                                         following uses:\r
123                                         <ul>\r
124                                         <li><b>XDR to XSD</b> - used to generate an XML schema from an XDR (XML Data Reduced schema) file. \r
125                                                 XDR was used by Microsoft prior to XSD becoming a W3C recommendation.  So, this needs\r
126                                                 to be supported for legacy reasons</li>\r
127                                         <li><b>XML to XSD</b> - used to generate an XML schema from an XML file</li> \r
128                                         <li><b>XSD to DataSet</b> - used to generate DataSet classes from an XSD schema file.  The\r
129                                                 DataSet classes created can then be used with XML data</li>\r
130                                         <li><b>XSD to Classes</b> - used to generate classes from an XSD schema file. The \r
131                                             classes created can be used with System.XML.Serialization.XMLSerializer \r
132                                             to read and write XML code that follows the schema</li>\r
133                                         <li><b>Classes to XSD</b> - used to generate an XML schema \r
134                                                 from type(s) in a assembly file. The \r
135                                                 XML schema created by the tool defines the XML format used \r
136                                                 by System.XML.Serialization.XMLSerializer</li>\r
137                                         </ul>\r
138                                 <li>Xsd.exe is used to manipulate XML schemas that \r
139                                         follow the http://www.w3.org/XML/Schema">XML Schema Definition (XSD)</a> language \r
140                                         recommended     by the <a href="http://w3.org/">World Wide Web Consortium (W3C)</a></li>\r
141                                         \r
142                                 <li>How this tool could be created:\r
143                                         <ul>\r
144                                                 <li>Write xsd.exe in C# and run on Mono</li>\r
145                                                 <li>Make sure we have XML Schema support in System.Xml.Schema.  Currently,\r
146                                                 it is wrapped around libxlst</li>\r
147                                                 <li>XML serialization support in System.Data classes</li>\r
148                                                 <li>Create the TypedDataSetGenerator class in System.Data</li>\r
149                                                 <li>Using CodeDOM or Reflection.Emit to create code</li>\r
150                                                 <li>Make sure DataSet, XmlDataDocument, and related classes \r
151                                                 are implemented fully</li>\r
152                                         </ul>\r
153                                 </li>   \r
154                                 
155                         </li>
156                         </ul>
157                 </li>
158                 
159                 <li><b>Application XML Configuration File Editor</b> - a tool
160                 to create and edit an application configuration file, such as,
161                 we have a .net application named Accouting.exe, the tool could edit
162                 the application configuration file Accounting.exe.config so a user could
163                 connect to the database used by the program.  This tool has not
164                 been created.</li>
165                 
166                 <li><b>Configuration Command-Line and GUI Tools for ADO.NET</b>.  
167                   These tools have not been started.  The tools would be written in
168                   C# and run on Mono. The
169                   configuration tool can be used to do the following:
170                   <ul> 
171                         <li>bebased on the Application XML Configuration File Editor</li>
172                         <li>setup DSNs for the ODBC and OLE-DB
173                                 providers and configurations for 
174                                 their underlying libraries (unixODBC and libgda)</li>
175                     <li>setup configurations for the Mono.Data.ProviderFactory
176                                 that Brian Ritchie created</li>
177                     <li>setup native database client library configurations too, such as,
178                                 freetds.conf for Microsoft SQL Server and Sybase</li>
179                   </ul>
180                 </li>
181
182 </ul>
183
184 ** Extra Classes in Mono ADO.NET
185
186  <p>An ADO.NET <a href="http://www.go-mono.com/provider-factory.html">Provider Factory</a> 
187     was created by Brian Ritchie.  The 
188         Provider Factory is a way to dynamically create
189         connections, commands, parameters, and data adapters based on configuration 
190         information.
191         
192 ** Current Status
193
194         <p>Various ADO.NET Providers have been created at various stages of 
195         development including: 
196         Firebird/Interbase, IBM DB2 Universal Database, MySQL, ODBC, OLE DB, Oracle,
197         PostgreSQL, SQL Lite, Sybase, Microsoft SQL Server, and TDS Generic.  
198         See their respective web page for more information.
199         
200         <p><b>Data Relations</b> via DataRelation, DataRelationCollection, and
201         other classes have not been implemented
202         
203         <p><b>Constraints</b> need lots of work
204         
205         <p><b>XML Schema Definition tool</b> xsd.exe that is included
206         in the .NET Framework has not been created for Mono
207         
208         <p><b>TypeDataSetGenerator</b> needs to be stubbed and implemented.
209                 
210         <p><b>DataSet, DataAdaptor, DataTable, DataRelation, DataRow, DataColumn,
211         DataColumnCollection, DataRowCollection, and others</b> need more work.  There are
212         many classes that are just stubs and need to be implemented.  Ville Palo has been
213         doing much testing here.
214
215         <p><b>XML support in System.Data</b> needs work.  This involves working on
216         the classes: DataSet, XmlDataDocument, and the method ExecuteXmlReader() that
217         exists in a provider's class that implements IDbCommand, and others.
218         Stuart Caborn has started the XML support in a DataSet.  Tim Coleman started
219         XML support in the ExecuteXmlReader() in a SqlCommand.  Ville Palo has been
220         heavily modifying DataSet, XmlDataDocument, and other classes for reading
221         and writing XML.  XML Serialization support in DataSet needs to be implemented.
222                 
223         <p><b>Integration with ASP.NET</b> has been created.  Data binding of
224         a DataTable in a DataSet to a System.Web.UI.WebControls.DataGrid works.  Data binding
225         of other types works too.
226         
227         <p><b>Database Access from ASP.NET</b>:
228         <ul>
229                 <li>Take a look at xsp in cvs and look at the examples in test: dbpage1.aspx
230                 and dbpage2.aspx:
231                         <ul>
232                                 <li>Notice that the namespace System.Data is imported via <b>import</b></li>
233                                 <li>A NameValueCollection is gotten using ConfigurationSettings.AppSetings. These
234                                 settings are gotten from the file server.exe.config which is a XML file.   The XML
235                                 file has a section appSettings.  In the appSettings section, you have keys 
236                                 for DBProviderAssembly, DBConnectionType, and DBConnectionString.
237                                 <ul>
238                                         <li><b>DBProviderAssembly</b> is the assembly of the ADO.NET provider.  
239                                               For example: 
240                                               "Mono.Data.PostgreSqlClient"</li>
241                                         <li><b>DBConnectionType</b> is the System.Type of the class that 
242                                               implements System.Data.IDbConnection that is found
243                                           in the DBProviderAssembly.  
244                                           For example: 
245                                           "Mono.Data.PostgreSqlClient.PgConnection"</li> 
246                                     <li><b>DBConnectionString</b> is the ConnectionString to set to the
247                                           IDbConnection object to use in opening a connection to a data source.
248                                           For Example: 
249                                           "hostaddr=127.0.0.1;user=monotest;password=monotest;dbname=monotest"</li>
250                                 </ul>
251                                 <li>The function GetConnectionData() gets the database provider assembly, connection type,
252                                 and connection string parameters if they exist; otherwise, it uses default values.  This is
253                                 done during the loading of the web page.</li>
254                                 <li>With the connection parameters, the assembly is loaded, the connection type is verified that
255                                 it implements IDbConnection and an instance of the class can be created, creates a instance
256                                 of the class, sets the connection string, and opens the connection.</li>
257                         </ul>
258                 </li>
259         </ul>
260         
261         <p><b>Integration with Windows.Forms</b> has not been started, such as, data binding 
262         to a System.Windows.Forms.DataGrid.  This may involve implementing many classes
263         in System.Windows.Forms and System.Data.
264         
265         <p><b>Integration with <a href="http://gtk-sharp.sourceforge.net/">GTK#</a></b> 
266         has not been started, such as, data binding
267         to a GtkTreeView.  This may involve creating new classes
268         to go between the glist data model and the ADO.NET data model.
269         Mike Kestner or Rachel Hestilov would be the best people to ask for help on GTK#.
270         
271         <p><b>Integration with QT#</b> has not been started.  Any information on 
272         how this can be done is appreciated.  Marcus would be the best 
273         person to ask about QT#.
274         
275         <p><b>Building System.Data</b>
276         
277         <p>The System.Data.dll gets built with the rest of the class library.
278         To compile the System.Data.dll assembly separately, you need:
279
280         <b>On Unix</b>
281
282         <ul>
283                 * update your mono sources. Be sure you have latest mcs.exe
284                   and .dll's, since there have been many fixes needed for
285                   compilation on Linux.
286
287                 * compile System.Data.dll:
288 <pre>
289  cd mcs/class/System.Data<br>
290  mcs --target library -o \
291     System.Data.dll @list
292 </pre>
293         </ul>
294
295         <b>On Windows</b>
296
297         <ul>
298                 * update your mono sources. Be sure you have latest mcs.exe
299                   and .dll's.  You can use the same method as Linux, 
300                   or you can use NAnt.
301
302                 * To use NAnt:
303
304 <pre>
305  cd mcs/class/System.Data
306  ../../nant/NAnt.exe
307 </pre>
308                         
309                 * This will automatically copy the System.Data.dll to Test.
310                   If you need to do a clean for the System.Data.dll assembly,<br><br>
311
312 <pre>
313  cd mcs/class/System.Data
314  ../../nant/NAnt.exe clean 
315 </pre>
316         </ul>
317
318 ** Testing
319
320 <ul>
321         <li>Testing connection-oriented classes are done 
322         via the provider specific tests
323         found in the mcs source at mcs/class</br>
324                 <table border=1>        
325                         <tr>
326                                 <td><b>Name</b></td>
327                                 <td><b>Assembly /</br> Namespace</b></td>
328                                 <td><b>Test</b></td>    
329                         </tr>           
330                         
331                         <tr>
332                                 <td>Microsoft</br> SQL</br> Server</br></td>
333                                 <td>System.Data /</br> System.Data.SqlClient</td>
334                                 <td>SqlTest.cs at</br> System.Data/Test</td>
335                         </tr>
336                         
337                         <tr>
338                                 <td>PostgreSQL</br> (Mono)</td>
339                                 <td>Mono.Data.PostgreSqlClient /</br> Mono.Data.PostgreSqlClient</td>
340                                 <td>PostgresTest.cs at</br> System.Data/Test</td>
341                         </tr>
342
343                         <tr>
344                                 <td>MySQL</br> (Mono)</td>
345                                 <td>Mono.Data.MySql /</br> Mono.Data.MySql</td>
346                                 <td>MySqlTest.cs at</br> Mono.Data.MySql/Test</td>
347                         </tr>
348
349                         <tr>
350                                 <td>Oracle</br> (Mono)</td>
351                                 <td>System.Data.OracleClient /</br> System.Data.OracleClient</td>
352                                 <td>TestOracleClient.cs at</br> System.Data.OracleClient</td>
353                         </tr>
354
355                         <tr>
356                                 <td>ODBC</br> (Mono)</td>
357                                 <td>System.Data.OracleClient /</br> System.Data.OracleClient</td>
358                                 <td>TestOracleClient.cs at</br> System.Data.OracleClient</td>
359                         </tr>
360                         
361                 </table>
362         
363
364         <li><a href="http://www.go-mono.com/testing.html">Testing non-connection classes</a> are 
365         done via mono's modified version of NUnit.
366                 <ul>
367                         <li>To run all the NUnit tests for Mono, you need the mcs source.  cd to the root
368                         of the mcs source.  To run it:
369                                 <ul>
370                                         <li>On Linux: make -f makefile test</li>
371                                         <li>On Windows: make test</li>
372                                 </ul>
373                         </li>
374                         <li>If you just want to run the NUnit tests for System.Data, you would cd into
375                         the mcs source at class/System.Data/Test and run it:
376                                 <ul>
377                                         <li>On Linux: make -f makefile test</li>
378                                         <li>On Windows: make test</li>
379                                 </ul>
380                         </li>
381                 </ul>
382         </li>
383                 
384 </ul>   
385