516c1c74d6e6f61b33feedfc55e39ec3dbfe1583
[mono.git] / web / 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><b>System.Data.SqlClient</b> 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         <ul>
109                 * <p>The idea in Microsoft .NET System.Data is to have
110                   a managed provider for each supported DBMS.
111                   
112                   <p>System.Data.SqlClient for Microsoft SQL Server.  See the
113                   Mono.Data.TdsClient provider.
114                   
115                   <p>Mono.Data.TdsClient for older Microsoft SQL Server
116                   and Sybase databases.  This has been started by Tim Coleman
117                   and will provide the functionality for System.Data.SqlClient
118                   and Mono.Data.SybaseClient.
119                   
120                   <p>Mono.Data.SybaseClient for Sybase SQL Server.  See the
121                   Mono.Data.TdsClient provider.
122                           
123                   <p>Mono.Data.PostgreSqlClient for PostgreSQL.  Started by
124                   Rodrigo Moya, Daniel Morgan, and Tim Coleman.  This provider 
125                   uses the PostgreSQL C API (libpq.so on Linux and pq.dll on
126                   Windows).
127           
128           <p>Mono.Data.MySql for MySQL client/server database.  Started by
129           Daniel Morgan using C# Bindings to MySQL from Brad Meril.  
130           This provider uses the MySQL C API (libmysqlclient.so on
131           Linux and libmySQL.dll on Windows).
132           
133           <p>Mono.Data.SqliteClient for the SQL Lite database.  Started by
134           Vladimir Vukicevic.  This provider uses 
135           <a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a> database engine.
136           It is used in mPhoto.
137           
138           <p>See Current Status for more information on these providers.
139           
140                   <p>Some providers we would like to have are
141                   Mono.Data.DB2, Mono.Data.miniSQL,  
142                   System.Data.OracleClient, Mono.Data.Interbase,
143                   Mono.Data.Berkeley, and SapDB.
144                   Others, of course, are welcomed.
145                                   
146         </ul>
147
148         <b>Step 5:</b> Create tools for ADO.NET
149
150         <ul>
151                 * <p><b>SQL# CLI - a command-line tool</b> to execute SQL commands,
152                   test connection strings, and connect to various ADO.NET
153                   providers in Mono.  The SQL# CLI has been started on and can be found in 
154                   mcs/tools/SqlSharp/SqlSharpCli.cs
155                   It is written in C# and runs on Mono and .NET
156
157                 * <p><b>SQL# GUI - a GUI tool</b> to execute SQL commands.  This
158                   has not been started.  The idea is to use the GnomeDbSqlEditor,
159                   GnomeDbBrowser, and GnomeDbGrid gtk+ widgets that exists 
160                   in libgnomedb# that is part of gtk#.  However, we could base it
161                   on System.Windows.Forms, but System.Windows.Forms in Mono 
162                   is not as complete as gtk#.  
163                 
164           <p>libgnomedb uses libgda for its data model and data access capabilities and
165           can be found <a href="http://www.gnome-db.org/">here</a>.  libgnomedb#
166           and gda# are part of <a href="http://gtk-sharp.sourceforge.net/">gtk#</a>
167           libgnomedb# is the C# bindings to libgnomedb which is a gtk+ GUI 
168           widget library for data access.       
169           gda# is the C# bindings to libgda which is a generic data access
170           library that has providers for many databases.
171           
172                 * <p><b>ADO.NET Configuration command-line and GUI tools</b>.  These tools have
173                   not been started.  They could become a part of SQL# though.  The
174                   configuration tool can be used to set up DSNs for the ODBC and OLE-DB
175                   providers.  The tools would be written in C# and run on Mono.
176                 
177         </ul>
178         
179 * Current Status
180         
181         <p>The<b>PostgreSQL</p> provider as Mono.Data.PostgreSqlClient can connect, 
182         execute commands, retrieve data via a Data Reader, read data in a DataTable 
183         in a DataSet via a Data Adapter, get a DataTable holding schema data,
184         and use input parameters in its SQL, and SQL errors and exceptions for PostgreSQL
185         are working. 
186         
187         <p>The <b>PostgreSQL</b> provider
188         has been moved from System.Data.SqlClient to Mono.Data.PostgreSqlClient
189         so System.Data.SqlClient can be used for the Microsoft SQL Server provider.
190                 
191         <p><b>System.Data.OleDb</b> is working with libgda (an OLE-DB/ADO data access for Unix).  
192         The C-Sharp bindings to libgda currently work - meaning they can compile, run, and you can connect to a
193         PostgreSQL database via libgda via the C-Sharp bindings to libgda.  Basic
194         functionality (execution of commands, data retrieval, transactions, etc) are
195         now working. Current focus is on filling up the missing pieces (Data adapters
196         mainly) and schema support.  We need help building libgda on Windows though.  libgda
197         builds find on linux though.  An inital implementation of GetSchemaTable() for
198         the OleDbDataReader has been checked into cvs.  GetSchemaTable() isn't correct for OleDb,
199         but the foundation is there.
200         
201         <p>Tim Coleman has just started on the <b>TDS</b> protocol support neccessary for the
202         <b>SqlClient, SybaseClient, and TdsClient</b> providers. The provider will be 
203         implemented in pure managed C#.  We are using FreeTDS and jTDS as references.  
204         The TDS provider will exist     in Mono.Data.TdsClient.  
205         The System.Data.SqlClient and Mono.Data.SybaseClient will
206         be based off of Mono.Data.TdsClient provider.  Currently, we are providing
207         the foundation for the TdsClient provider.  Next step is to implement the TDS
208         protocol in C#.
209         
210         <p><b>ODBC</b> support has been started by Brian Ritchie.\r
211         It uses unixODBC on Linux and uses native ODBC support on Windows.\r
212         There is basic implementations of \r
213     OdbcConnection, OdbcCommand, OdbcDataReader, OdbcParameter, and \r
214     OdbcParameterCollection.  The provider can execute queries and display result sets \r
215     (and ExecuteNonQuery too).  Currently, developers are working on the Parameter & \r
216     Transaction support.  It was tested on Debian against a DB2 7.2 UDB.  It was\r
217     also tested on Windows XP against a Microsoft SQL Server 2000 database.\r
218         
219         <p><b>Mono.Data.MySql</b> is an ADO.NET provider for 
220         the <b>MySQL</b> client/server database management system
221         that uses the MySQL C Client Library.   Currently, we can connect, 
222         execute simple commands, and
223         retrieve results using a data reader.  A schema DataTable has been partially 
224         implemented which is returned from GetSchemaTable() in MySqlDataReader.
225         The shared client libraries 
226         between windows version and linux are different: windows has libmySQL.dll 
227         while linux has libmysqlclient.so.  This is handled by the 
228         file etc/mono/config which is mapped by the mono runtime in knowing
229         which native shared library to load.  In cvs, this file is mono/config.in and
230         can be modified with a text editor.  
231         The C# Bindings to MySQL are thanks to Brad Meril.
232
233         <p><b>Mono.Data.SqliteClient</b> is an ADO.NET provider for
234         the <a href"http://www.hwaci.com/sw/sqlite/download.html">SQL Lite</a>
235         database.  There is SQL Lite binaries for Linux and Windows.  sqlite.dll on Windows 
236         and sqlite.so on Linux. The SQL Lite proivder
237         was contributed by Vladimir Vukicevic.
238                 
239         <p><b>DataSet, DataAdaptor, DataTable, DataRelation, DataRow, DataColumn,
240         DataColumnCollection, DataRowCollection, and others</b> need more work.  There are
241         many classes that are just stubs and need to be implemented.  
242                 
243         <p><b>Integration with ASP.NET</b> has not been started, such as, data binding
244         to a System.Web.UI.WebControls.DataGrid.  This may involve implementing many classes
245         in System.Web and System.Data.  Gonzalo, Gaurav, Leen, Patrik, Duncan, and others are 
246         working very hard on the ASP.NET support. If you want to help, 
247         contact <a href="mailto:gonzalo@ximian.com">Gonzalo Paniagua Javier</a>
248         
249         <p><b>Integration with Windows.Forms</b> has not been started, such as, data binding 
250         to a System.Windows.Forms.DataGrid.  This may involve implementing many classes
251         in System.Windows.Forms and System.Data.
252         
253         <p><b>Integration with <a href="http://gtk-sharp.sourceforge.net/">GTK#</a></b> 
254         has not been started, such as, data binding
255         to a GtkTreeView.  This may involve creating new classes
256         to go between the glist data model and the ADO.NET data model.
257         Mike Kestner would be the best person to ask for help on GTK#.
258         
259         <p><b>Integration with QT#</b> has not been started.  Any information on 
260         how this can be done is appreciated.  Adam Treat would be the best 
261         person to ask about QT#.
262         
263         <p><b>Integration with GDA#</b> has not been started.  It is 
264         included in the GTK# project, GDA# 
265         does not require GTK+ nor GNOME.  GDA# is C# bindings 
266         to <a href="http://www.gnome-db.org/">GDA</a> which
267         is an ADO/OLE-DB like layer for Linux provided as a C library.  Classes
268         that would bind data between the ADO.NET data model and the GDA data model will
269         need to be created.  Rodrigo Moya is the best person to contact about this.
270         
271         <p><b>Integration with GnomeDb#</b> has not been started.  It is
272         included in the GTK# project and uses GDA# for its data access model.
273         Creating classes to bind data between the data model in ADO.NET 
274         and the data model that exists in GDA# and GnomeDb# will
275         need to be started.  GnomeDb# is C# bindings to
276         <a href="http://www.gnome-db.org/">GnomeDb</a> which uses 
277         <a href="http://www.gnome-db.org/">GDA</a> as its data access layer.  GnomeDb
278         is a C API in a library that contains
279         gtk+ widgets (GUI controls) for data access.  There are some nifty widgets
280         (GUI controls) that can be used, such as, GnomeDbGrid, GnomeDbBrowswer, 
281         GnomeDbSqlEditor, GnomeDbList, GnomeDbLogin, GnomeDbReportEditor, GnomeDbTableEditor, 
282         GnomeDbCombo, and GnomeDbForm.  Rodrigo Moya is the best person to contact.
283                 
284         <p><b>XML support in System.Data</b> needs to be started.  This involves working on
285         the classes: DataSet, XmlDataDocument, and the method ExecuteXmlReader() that
286         exists in a provider's class that implements IDbCommand, and others.
287         
288         <p><b>ADO.NET Multiplexor Provider</b> needs to be created.  This is not
289         part of Microsoft .NET, but it needs to be able to run on Microsoft .NET
290         and Mono.  This provider can be a generic provider, much like the ODBC.NET and
291         OLEDB.NET providers are, but be written in 100% C# and be configurable via
292         a configuration file.  This provider will multiplex to other providers
293         that exist.  If one does not exist for a given DBMS, 
294         default to the ODBC or OLEDB .NET provider.  Or it could be a class
295         that its sole duty is to dynamically create a provider's Connection class
296         based on a configuration file.  It can provide some utility functions as
297         well that can be used in all or most of the providers, such as, what
298         parameter marker character should be used: a colon, at, question mark,
299         or square brackets.
300         
301         <p>According to Gonzalo, this is how it could be implemented:
302 \r
303         <p>After some work done in System.Configuration, you can now do something\r
304     like:   \r
305 \r
306         <p>\r
307  <pre>\r
308  // Get an instance of the multiplexor from machine.config file\r
309  // Can be overriden in the application config file     \r
310  object o = ConnectionSettings.GetConfig ("mono.data/multiplexor");\r
311  if (o == null)\r
312         --- error\r
313     \r
314  Multiplexor mp = (Multiplexor) o;\r
315     \r
316  // may be a string [] argument can help passing arguments\r
317  IDbConnection cnc = mp.CreateConnection (providerName);\r
318     \r
319  and in the machine.config file:\r
320 \r
321   <configuration>\r
322    <configSections>\r
323     <section name="mono.data"\r
324       type="Mono.Data.MultiplexorSectionHandler,Mono.Data" />\r
325     ....\r
326    </configSections>\r
327    ...\r
328    <sectionGroup name="mono.data">\r
329      <multiplexor>\r
330        <add provider="PostgreSQL" type="Mono.Data.PostgreSQLClient,Mono.Data"\r
331           validate="false" parameters="USER=xxx;HOST=127.0.0.1;DBNAME=xxx" />\r
332      </multiplexor>\r
333    </sectionGroup>\r
334   </configuration>\r
335 \r
336  validate="false" tells MultiplexorSectionHandler not to load the Type\r
337  until an instance is required. You can add more attributes or whatever\r
338  inside <multiplexor> as long as MultiplexorSectionHandler parses it.\r
339 \r
340     public class MultiplexorSectionHandler :\r
341     IConfigurationSectionHandler\r
342     {\r
343         public object Create (object parent, object configContext,\r
344         XmlNode section)\r
345         {\r
346             Multiplexor mp;\r
347         // Here you get the ChildNodes and set up a Multiplexor\r
348         // instance that will hold the information needed to create \r
349         // instances of each provider. Only one instance will be \r
350         // created by the config system.\r
351             return mp;\r
352         }\r
353     }\r
354 \r
355  This way, if our providers works with MS, the user can test them in both\r
356  MS and mono by just adding a few lines to machine.config (i still have\r
357  to upload a default machine.config file for mono). And this is the .NET\r
358  way of doing it (of course, if you prefer, you can use the other config\r
359  file. I just wanted to make people aware of this feature that now works\r
360  on mono).\r
361 </pre>
362         
363         <p><b>Building System.Data</b>
364         
365         <p>The System.Data.dll gets built with the rest of the class library.
366         To compile the System.Data.dll assembly separately, you need:
367
368         <b>On Unix</b>
369
370         <ul>
371                 * update your mono sources. Be sure you have latest mcs.exe
372                   and .dll's, since there have been many fixes needed for
373                   compilation on Linux.
374
375                 * compile System.Data.dll:
376 <pre>
377  cd mcs/class/System.Data<br>
378  mcs --target library -o System.Data.dll @list
379 </pre>
380         </ul>
381
382         <b>On Windows</b>
383
384         <ul>
385                 * update your mono sources. Be sure you have latest mcs.exe
386                   and .dll's.  You can use the same method as Linux, 
387                   or you can use NAnt.
388
389                 * To use NAnt:
390
391 <pre>
392  cd mcs/class/System.Data
393  ../../nant/NAnt.exe
394 </pref>
395                         
396                 * This will automatically copy the System.Data.dll to Test.
397                   If you need to do a clean for the System.Data.dll assembly,<br><br>
398
399 <pre>
400  cd mcs/class/System.Data
401  ../../nant/NAnt.exe clean
402  
403 </pre>
404         </ul>
405