2003-01-19 Daniel Morgan <danmorg@sc.rr.com>
[mono.git] / web / odbc
1 * ODBC Data Provider
2 <ul>
3         <li>Exists in namespace System.Data.Odbc and assembly System.Data
4         
5         <li>Works on Windows and Linux. Should have no problems working on UNIX too.
6         
7         <li>Works on Windows via the native Windows odbc32.dll
8         
9         <li>Works on Linux via:
10         
11         <ul>
12                 <li><a href="http://www.unixodbc.org/">unixODBC</a> which has 
13                         commercial support 
14                         from <a href="http://www.easysoft.com/">Easysoft</a></li>
15                         
16                 <li><a href="http://www.iodbc.org/">iODBC</a> which has 
17                     a commercial support 
18                     from <a href="http://oplweb.openlinksw.com:8080/download/">OpenLink Software</a></li>
19         </ul>
20         
21         <li>List of unixODBC <a href="http://www.unixodbc.org/drivers.html">drivers</a>
22         
23         <li>List of <a href="http://ourworld.compuserve.com/homepages/Ken_North/odbcvend.htm">ODBC Vendors</a>
24         
25         <li>ODBC can connect to various databases which has an ODBC driver installed:
26         <ul> 
27                   <li><a href="http://www.mysql.com/">MySQL</a> 
28                   <li><a href="http://www.postgresql.org/">PostgreSQL</a>
29                   <li><a href="http://www.oracle.com/">Oracle</a>
30                   <li><a href="http://www.borland.com/products/downloads/download_interbase.html">Interbase</a>
31                   <li><a href="http://www.sybase.com/downloads">Sybase</a> and
32                   <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a> (
33                   via <a href="http://www.freetds.org/">FreeTDS</a> on UNIX)
34                   <li><a href="http://www-3.ibm.com/software/data/db2/">IBM DB2 Universal Database</a>
35                   <li><a href="http://www.microsoft.com/office/access/default.asp">MS Access</a> 
36                   (via <a href="http://mdbtools.sourceforge.net/">MDB Tools</a> on UNIX)
37         </ul>
38                 
39         <li>ODBC Provider created by Brian Ritchie.</li>
40         
41         <li>Does not support trusted connections</li>
42 </ul>
43         
44 ** Current Status
45
46 <ul>
47         <li>Can Connect on:
48         <ul>
49                 <li>Windows via native Windows odbc32.dll</a></li>
50                 <li>Linux via:
51                 <ul>
52                         <li>unixODBC's libodbc.so</li>
53                         <li>iODBC's libiodbc.so</li>
54                 </ul>
55                 </li>
56         </ul>
57         </li>
58         
59         <li>Various databases have been tested using their
60            ODBC drivers: MySQL, PostgreSQL, Oracle, IBM DB2, and Microsoft SQL Server</li>
61            
62         <li>Can execute non-query commands via ExecuteNonQuery of a OdbcCommand</li>
63         
64         <li>Can execute aggreates and retrieve a single row single column result via
65         ExecuteScalar of a OdbcCommand</li>
66         
67         <li>Can execute queries via ExecuteReader of a OdbcCommand and 
68         retrieve results using an OdbcDataReader</li>
69         
70         <li>Can get a DataTable containing schema info via GetSchemaTable() in a OdbcDataReader</li>
71         
72         <li>Can Fill a DataTable in a DataSet via an OdbcDataAdapter</li>
73 </ul>
74         
75 ** Action Plan
76
77 <ul>
78         
79         <li>Fixing bugs
80         
81         <li>Testing with other setups
82 </ul>
83
84 ** Testing ODBC provider
85
86 <p>Test Mono's ODBC provider System.Data.Odbc with the MySQL ODBC driver MyODBC
87
88 <p><ul>
89         <li>Take a look at OdbcTest.cs in mcs/class/System.Data/Test</li>
90
91         <li>Here is a ConnectionString format if you have a DSN setup: 
92 <pre>
93 "DSN=dataSetName;UID=username;PWD=password"
94 </pre>
95         </li>
96         <li>Here is a ConnectionString format if you do not have DSN (have not
97         gotten this to work):
98 <pre>
99 "DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=;DATABASE=pubs"
100 </pre>
101         </li>
102         <li>C# Example:
103 <pre>
104  using System;
105  using System.Data;
106  using System.Data.Odbc;
107  
108  public class Test 
109  {
110     public static void Main(string[] args)
111     {
112                 // have an ODBC DSN setup named MYSQLDSN
113                 // that accesses a MySQL database via
114                 // MyODBC driver for ODBC with a
115                 // hostname of localhost and database test
116        string connectionString = 
117           "DSN=MYSQLDSN;" +
118           "UID=mysql;" +
119           "PWD=;";
120        IDbConnection dbcon;
121        dbcon = new OdbcConnection(connectionString);
122        IDbCommand dbcmd = dbcon.CreateCommand();
123        // requires a table to be created named employee
124        // with columns firstname and lastname
125        // such as,
126        //        CREATE TABLE employee (
127        //           firstname varchar(32),
128        //           lastname varchar(32));
129        string sql = 
130            "SELECT firstname, lastname " +
131            "FROM employee";
132        dbcmd.ConnectionString = sql;
133        IDataReader reader = dbcmd.ExecuteReader();
134        while(reader.Read()) {
135             string FirstName = reader["firstname"];
136             string LastName = reader["lastname"];
137             Console.WriteLine("Name: " + 
138                 FirstName + " " + LastName);
139        }
140        // clean up
141        reader.Close();
142        reader = null;
143        dbcmd.Dispose();
144        dbcmd = null;
145        dbcon.Close();
146        dbcon = null;
147     }
148  }
149 </pre>
150         </li>
151         <li>Building C# Example:
152         <ul>
153                 <li>Save the example to a file, such as, TestExample.cs</li>
154                 <li>Build on Linux:
155 <pre>
156         mcs TestExample.cs -r System.Data.dll
157 </pre>
158                 </li>
159                 <li>Build on Windows via Cygwin:
160 <pre>
161         mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
162              TestExample.cs \
163              -lib:C:/cygwin/home/MyHome/mono/install/lib \
164              -r System.Data.dll
165 </pre>
166                 </li>
167         </ul>
168         </li>
169         <li>Running the Example:
170 <pre>
171 mono TestExample.exe
172 </pre>
173         </li>
174         
175 </ul>