*** empty log message ***
[mono.git] / doc / ado-net
1 * ADO.NET
2
3         The coordinator for the ADO.NET implementation is 
4         <a href="mailto:rodrigo@ximian.com">Rodrigo Moya</a>, 
5         with the collaboration of: 
6         <a href="mailto:danmorg@sc.rr.com">Daniel Morgan</a>, 
7         <a href="mailto:tim@timcoleman.com">Tim Coleman</a>,
8         <a href="mailto:brianlritchie@hotmail.com">Brian Ritchie</a>, and
9         <a href="mailto:vladimir@pobox.com">Vladimir Vukicevic</a>.
10         
11
12 * Action plan
13
14         The current plan to implement ADO.NET is as follows:
15
16         <b>Step 1:</b><a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOleDb.asp?frame=true">System.Data.OleDb</a> Provider:
17                 
18         <ul>
19                 * <p>On Unix systems: System.Data.OleDb uses the
20                 <a href="http://www.gnome-db.org/">LibGDA</a>
21                  engine.   This provider was started by Rodrigo Moya and Tim Coleman.
22
23                   <p>LibGDA is a data access engine like ADO/OLE-DB, but for Unix.  The 
24                   GDA in libGDA stands for GNU/GNOME Data Access, but it does not require GNOME.
25                   It only requires glib2 and libxml2.  LibGDA is used by 
26                   libgnomedb, GNOME-DB, and gaSQL.  glib2 and libxml2 both work on Linux
27                   and Windows.
28                   
29                   <p>There is work under way to get libgda working under 
30                   Windows using Cygwin by the GNOME-DB developers, but we have not
31                   been successful yet.
32                   
33                   <p>LibGDA has providers for 
34                   <a href="http://www.mysql.com/">MySQL</a>, 
35                   <a href="http://www.postgresql.org/">PostgreSQL</a>, 
36                   XML, 
37                   ODBC (via <a href="http://www.unixodbc.org/">unixODBC</a>),
38                   <a href="http://www.oracle.com/">Oracle</a>, 
39                   <a href="http://www.borland.com/products/downloads/download_interbase.html">Interbase</a>, 
40                   <a href="http://www.sybase.com/downloads">Sybase</a> and 
41                   <a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a> (
42                   via <a href="http://www.freetds.org/">FreeTDS</a>), 
43                   <a href="http://www-3.ibm.com/software/data/db2/">IBM DB2 Universal Database</a>,
44                   <a href="http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a>,
45                   and <a href="http://www.microsoft.com/office/access/default.asp">MS Access</a> 
46                   (via <a href="http://mdbtools.sourceforge.net/">MDB Tools</a>).
47                   
48         </ul>
49
50         <b>Step 2:</b> <a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdatasqlclient.asp?frame=true">System.Data.SqlClient</a> Provider:
51
52         <ul>
53                 * <p>System.Data.SqlClient will become a
54                   provider for Microsoft SQL Server, both on Windows and
55                   Linux, to be compatible with applications written
56                   for the Microsoft .NET Development Framework.
57
58                 * <p>The <a href="http://wwww.go-mono.com/tds-providers.html">SqlClient and SybaseClient Design</a>
59                   states that System.Data.SqlClient will be written completely in
60                   C#.  FreeTDS and jTDS projects will be used as references on how to
61                   implement the TDS protocol.  SqlClient will use common internal code with SybaseClient
62                   and TdsClient.
63           
64                 * <p><a href="http://www.freetds.org/">FreeTDS</a> 
65                   is a collection of free native C libraries: tds, dblib, 
66                   and ctlib for accessing TDS protocol databases like
67                   Microsoft SQL Server and Sybase.
68                   
69                 * <p><a href="http://jtds.sf.net/">jTDS</a> 
70                   is a 100% Java JDBC Provider implementing the TDS protocol
71                   which allows data access to Microsoft SQL Server and
72                   Sybase databases.       
73                   
74         </ul>
75
76         <b>Step 3:</b> <a href="http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml&frame=true">System.Data.Odbc</a> Provider:
77         
78         <ul>
79                 * An ADO.NET Provider for ODBC has been created in
80                   System.Data.Odbc by Brian Ritchie for those using ODBC.
81                   
82                 * <p>On Unix, the provider uses <a href="http://www.unixodbc.org/">unixODBC</a> 
83                   for its ODBC connectivity.  The ODBC provider uses the libodbc.dll that
84                   comes with unixODBC.  
85                   
86                   <p>There is an alternative to unixODBC, <a href="http://www.iodbc.org/">iODBC</a>, 
87                   but it has not been tested with the ODBC provider.
88                 
89                 * On Windows, the provider uses the native ODBC libraries (odbc32.dll) that comes 
90                   with Windows since unixODBC is supposed to be compatible with that.
91                   If you do not have odbc32.dll on Windows, get the latest MDAC 
92                   from Microsoft.  
93                   
94                 * <p>The mapping between these native shared libraries is handled 
95                   in etc/mono/config
96                   
97                   <p>In mono cvs, the file is mono/data/config.in                         
98                   
99                   <p>unixODBC has providers for:
100                   Oracle, Microsoft SQL Server and Sybase (via FreeTDS), 
101                   MySQL, PostgreSQL, Informix, IBM DB2 Universal Database, 
102                   Interbase, miniSQL (mSQL), AdabasD, Empress, Ingres, Sap DB, and others.
103                   
104         </ul>
105
106         <b>Step 4:</b> Other ADO.NET providers:
107
108         <p>The idea in Microsoft .NET System.Data is to have
109                   a managed provider for each supported DBMS.
110                   
111                   <ul>
112                   
113                   <li><p>System.Data.SqlClient for Microsoft SQL Server.  See the
114                   Mono.Data.TdsClient provider.
115                   
116                   <li><p>Mono.Data.TdsClient for older Microsoft SQL Server
117                   and Sybase databases.  This has been started by Tim Coleman
118                   and will provide the functionality for System.Data.SqlClient
119                   and Mono.Data.SybaseClient.
120                   
121                   <li><p>Mono.Data.SybaseClient for Sybase SQL Server.  See the
122                   Mono.Data.TdsClient provider.
123                           
124                   <li><p>Mono.Data.PostgreSqlClient for PostgreSQL.  Started by
125                   Rodrigo Moya, Daniel Morgan, and Tim Coleman.  This provider 
126                   uses the PostgreSQL C API (libpq.so on Linux and pq.dll on
127                   Windows).
128           
129           <li><p>Mono.Data.MySql for MySQL client/server database.  Started by
130           Daniel Morgan using C# Bindings to MySQL from Brad Meril.  
131           This provider uses the MySQL C API (libmysqlclient.so on
132           Linux and libmySQL.dll on Windows).
133           
134           <li><p>Mono.Data.SqliteClient for the SQL Lite database.  Started by
135           Vladimir Vukicevic.  This provider uses 
136           <a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a> database engine.
137           It is used in mPhoto.
138           
139           </ul>
140           
141           <p>See Current Status for more information on these providers.
142           
143                   <p>Some providers we would like to have are
144                   Mono.Data.DB2, Mono.Data.miniSQL,  
145                   System.Data.OracleClient, Mono.Data.Interbase,
146                   Mono.Data.Berkeley, and SapDB.
147                   Others, of course, are welcomed.
148                                   
149         </ul>
150
151         <b>Step 5:</b> Create tools for ADO.NET
152
153         <ul>
154                 * <p><b>SQL# CLI - a command-line tool</b> to execute SQL commands,
155                   test connection strings, and connect to various ADO.NET
156                   providers in Mono.  The SQL# CLI has been started on and can be found in 
157                   mcs/tools/SqlSharp/SqlSharpCli.cs
158                   It is written in C# and runs on Mono and .NET
159
160                 * <p><b>SQL# GUI - a GUI tool</b> to execute SQL commands.  This
161                   has not been started.  The idea is to use the GnomeDbSqlEditor,
162                   GnomeDbBrowser, and GnomeDbGrid gtk+ widgets that exists 
163                   in libgnomedb# that is part of gtk#.  However, we could base it
164                   on System.Windows.Forms, but System.Windows.Forms in Mono 
165                   is not as complete as gtk#.  
166                 
167           <p>libgnomedb uses libgda for its data model and data access capabilities and
168           can be found <a href="http://www.gnome-db.org/">here</a>.  libgnomedb#
169           and gda# are part of <a href="http://gtk-sharp.sourceforge.net/">gtk#</a>
170           libgnomedb# is the C# bindings to libgnomedb which is a gtk+ GUI 
171           widget library for data access.       
172           gda# is the C# bindings to libgda which is a generic data access
173           library that has providers for many databases.
174           
175                 * <p><b>Configuration Command-Line and GUI Tools for ADO.NET</b>.  
176                   These tools have
177                   not been started.  They could become a part of SQL# though.  The
178                   configuration tool can be used to set up DSNs for the ODBC and OLE-DB
179                   providers and configurations for 
180                   their underlying libraries (unixODBC and libgda). The configuration
181                   tool could set database client library configurations too, such as,
182                   freetds.conf for Microsoft SQL Server and Sybase, 
183                   The tools would be written in C# and run on Mono.
184                 
185         </ul>
186         
187 * Current Status
188         
189         <p>The <b>PostgreSQL</b> provider in Mono.Data.PostgreSqlClient can connect, 
190         execute commands, retrieve data via a Data Reader, read data in a DataTable 
191         in a DataSet via a Data Adapter, get a DataTable holding schema data,
192         and use input parameters in its SQL, and SQL errors and exceptions for PostgreSQL
193         are working.
194                 
195         <p><b>System.Data.OleDb</b> is working with libgda (an OLE-DB/ADO data access for Unix).  
196         The C-Sharp bindings to libgda currently work - meaning they can compile, run, and you can connect to a
197         PostgreSQL database via libgda via the C-Sharp bindings to libgda.  Basic
198         functionality (execution of commands, data retrieval, transactions, etc) are
199         now working. Current focus is on filling up the missing pieces (Data adapters
200         mainly) and schema support.  We need help building libgda on Windows though.  libgda
201         builds find on linux though.  An inital implementation of GetSchemaTable() for
202         the OleDbDataReader has been checked into cvs.  GetSchemaTable() isn't correct for OleDb,
203         but the foundation is there.
204         
205         <p>Tim Coleman has just started on the <b>TDS</b> protocol support neccessary for the
206         <b>SqlClient, SybaseClient, and TdsClient</b> providers. The provider will be 
207         implemented in pure managed C#.  We are using FreeTDS and jTDS as references.  
208         The TDS provider will exist     in Mono.Data.TdsClient.  
209         The System.Data.SqlClient and Mono.Data.SybaseClient will
210         be based off of Mono.Data.TdsClient provider.  Currently, we are providing
211         the foundation for the TdsClient provider.  Next step is to implement the TDS
212         protocol in C#.
213         
214         <p><b>ODBC</b> support has been started by Brian Ritchie.\r
215         It uses unixODBC on Linux and uses native ODBC support on Windows.\r
216         There is basic implementations of \r
217     OdbcConnection, OdbcCommand, OdbcDataReader, OdbcParameter, and \r
218     OdbcParameterCollection.  The provider can execute queries and display result sets \r
219     (and ExecuteNonQuery too).  Currently, developers are working on the Parameter & \r
220     Transaction support.  It was tested on Debian against a DB2 7.2 UDB.  It was\r
221     also tested on Windows XP against a Microsoft SQL Server 2000 database.\r
222         
223         <p><b>Mono.Data.MySql</b> is an ADO.NET provider for 
224         the <b>MySQL</b> client/server database management system
225         that uses the MySQL C Client Library.   Currently, we can connect, 
226         execute simple commands, and
227         retrieve results using a data reader.  A schema DataTable has been partially 
228         implemented which is returned from GetSchemaTable() in MySqlDataReader.
229         The shared client libraries 
230         between windows version and linux are different: windows has libmySQL.dll 
231         while linux has libmysqlclient.so.  This is handled by the 
232         file etc/mono/config which is mapped by the mono runtime in knowing
233         which native shared library to load.  In cvs, this file is mono/config.in and
234         can be modified with a text editor.  
235         The C# Bindings to MySQL are thanks to Brad Meril.
236
237         <p><b>Mono.Data.SqliteClient</b> is an ADO.NET provider for
238         the <a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a>
239         database.  There is SQL Lite binaries for Linux and Windows.  sqlite.dll on Windows 
240         and sqlite.so on Linux. The SQL Lite proivder
241         was contributed by Vladimir Vukicevic.
242                 
243         <p><b>DataSet, DataAdaptor, DataTable, DataRelation, DataRow, DataColumn,
244         DataColumnCollection, DataRowCollection, and others</b> need more work.  There are
245         many classes that are just stubs and need to be implemented.  
246                 
247         <p><b>Integration with ASP.NET</b> has not been started, such as, data binding
248         to a System.Web.UI.WebControls.DataGrid.  This may involve implementing many classes
249         in System.Web and System.Data.  Gonzalo, Gaurav, Leen, Patrik, Duncan, and others are 
250         working very hard on the ASP.NET support. If you want to help, 
251         contact <a href="mailto:gonzalo@ximian.com">Gonzalo Paniagua Javier</a>
252         
253         <p><b>Integration with Windows.Forms</b> has not been started, such as, data binding 
254         to a System.Windows.Forms.DataGrid.  This may involve implementing many classes
255         in System.Windows.Forms and System.Data.
256         
257         <p><b>Integration with <a href="http://gtk-sharp.sourceforge.net/">GTK#</a></b> 
258         has not been started, such as, data binding
259         to a GtkTreeView.  This may involve creating new classes
260         to go between the glist data model and the ADO.NET data model.
261         Mike Kestner would be the best person to ask for help on GTK#.
262         
263         <p><b>Integration with QT#</b> has not been started.  Any information on 
264         how this can be done is appreciated.  Adam Treat would be the best 
265         person to ask about QT#.
266         
267         <p><b>Integration with GDA#</b> has not been started.  It is 
268         included in the GTK# project, GDA# 
269         does not require GTK+ nor GNOME.  GDA# is C# bindings 
270         to <a href="http://www.gnome-db.org/">GDA</a> which
271         is an ADO/OLE-DB like layer for Linux provided as a C library.  Classes
272         that would bind data between the ADO.NET data model and the GDA data model will
273         need to be created.  Rodrigo Moya is the best person to contact about this.
274         
275         <p><b>Integration with GnomeDb#</b> has not been started.  It is
276         included in the GTK# project and uses GDA# for its data access model.
277         Creating classes to bind data between the data model in ADO.NET 
278         and the data model that exists in GDA# and GnomeDb# will
279         need to be started.  GnomeDb# is C# bindings to
280         <a href="http://www.gnome-db.org/">GnomeDb</a> which uses 
281         <a href="http://www.gnome-db.org/">GDA</a> as its data access layer.  GnomeDb
282         is a C API in a library that contains
283         gtk+ widgets (GUI controls) for data access.  There are some nifty widgets
284         (GUI controls) that can be used, such as, GnomeDbGrid, GnomeDbBrowswer, 
285         GnomeDbSqlEditor, GnomeDbList, GnomeDbLogin, GnomeDbReportEditor, GnomeDbTableEditor, 
286         GnomeDbCombo, and GnomeDbForm.  Rodrigo Moya is the best person to contact.
287                 
288         <p><b>XML support in System.Data</b> needs to be started.  This involves working on
289         the classes: DataSet, XmlDataDocument, and the method ExecuteXmlReader() that
290         exists in a provider's class that implements IDbCommand, and others.
291         
292         <p><b>ADO.NET Multiplexor Provider</b> needs to be created.  This is not
293         part of Microsoft .NET, but it needs to be able to run on Microsoft .NET
294         and Mono.  This provider can be a generic provider, much like the ODBC.NET and
295         OLEDB.NET providers are, but be written in 100% C# and be configurable via
296         a configuration file.  This provider will multiplex to other providers
297         that exist.  If one does not exist for a given DBMS, 
298         default to the ODBC or OLEDB .NET provider.  Or it could be a class
299         that its sole duty is to dynamically create a provider's Connection class
300         based on a configuration file.  It can provide some utility functions as
301         well that can be used in all or most of the providers, such as, what
302         parameter marker character should be used: a colon, at, question mark,
303         or square brackets.
304         
305         <p>According to Gonzalo, this is how it could be implemented:
306 \r
307         <p>After some work done in System.Configuration, you can now do something\r
308     like:   \r
309 \r
310         <p>\r
311  <pre>\r
312  // Get an instance of the multiplexor from machine.config file\r
313  // Can be overriden in the application config file     \r
314  object o = ConnectionSettings.GetConfig \r
315                ("mono.data/multiplexor");\r
316  if (o == null)\r
317         --- error\r
318     \r
319  Multiplexor mp = (Multiplexor) o;\r
320     \r
321  // may be a string [] argument can help passing arguments\r
322  IDbConnection cnc = mp.CreateConnection (providerName);\r
323 </pre>    \r
324 \r
325         <p>and in the machine.config file:\r
326 \r
327 <pre>\r
328   &lt;configuration&gt;\r
329    &lt;configSections&gt;\r
330     &lt;section name="mono.data"\r
331       type="Mono.Data.MultiplexorSectionHandler,Mono.Data"/&gt;\r
332     ....\r
333    &lt;/configSections>\r
334    ...\r
335    &lt;sectionGroup name="mono.data"&gt;\r
336      &lt;multiplexor&gt;\r
337        &lt;add provider="PostgreSQL" \r
338           type="Mono.Data.PostgreSQLClient,Mono.Data"\r
339           validate="false" \r
340           parameters="USER=xxx;HOST=127.0.0.1;DBNAME=xxx"/&gt;\r
341      &lt;/multiplexor&gt;\r
342    &lt;/sectionGroup&gt;\r
343   &lt;/configuration&gt;\r
344 </pre>\r
345 \r
346         <p>validate="false" tells MultiplexorSectionHandler not to load the Type\r
347         until an instance is required. You can add more attributes or whatever\r
348         inside <multiplexor> as long as MultiplexorSectionHandler parses it.\r
349 \r
350 <pre>\r
351 public class MultiplexorSectionHandler :\r
352 IConfigurationSectionHandler\r
353 {\r
354     public object Create (object parent, \r
355       object configContext,\r
356       XmlNode section)\r
357     {\r
358        Multiplexor mp;\r
359        // Here you get the ChildNodes and \r
360        // set up a Multiplexor\r
361        // instance that will hold the information \r
362        // needed to create \r
363        // instances of each provider. Only one \r
364        // instance will be \r
365        // created by the config system.\r
366             return mp;\r
367     }\r
368  }\r
369 </pre>\r
370         <p>This way, if our providers works with MS, the user can test them in both\r
371         MS and mono by just adding a few lines to machine.config (i still have\r
372         to upload a default machine.config file for mono). And this is the .NET\r
373         way of doing it (of course, if you prefer, you can use the other config\r
374         file. I just wanted to make people aware of this feature that now works\r
375         on mono).\r
376         
377         <p><b>Building System.Data</b>
378         
379         <p>The System.Data.dll gets built with the rest of the class library.
380         To compile the System.Data.dll assembly separately, you need:
381
382         <b>On Unix</b>
383
384         <ul>
385                 * update your mono sources. Be sure you have latest mcs.exe
386                   and .dll's, since there have been many fixes needed for
387                   compilation on Linux.
388
389                 * compile System.Data.dll:
390 <pre>
391  cd mcs/class/System.Data<br>
392  mcs --target library -o \
393     System.Data.dll @list
394 </pre>
395         </ul>
396
397         <b>On Windows</b>
398
399         <ul>
400                 * update your mono sources. Be sure you have latest mcs.exe
401                   and .dll's.  You can use the same method as Linux, 
402                   or you can use NAnt.
403
404                 * To use NAnt:
405
406 <pre>
407  cd mcs/class/System.Data
408  ../../nant/NAnt.exe
409 </pre>
410                         
411                 * This will automatically copy the System.Data.dll to Test.
412                   If you need to do a clean for the System.Data.dll assembly,<br><br>
413
414 <pre>
415  cd mcs/class/System.Data
416  ../../nant/NAnt.exe clean 
417 </pre>
418         </ul>
419