Merge branch 'master' of github.com:tgiphil/mono
[mono.git] / web / odbc
1 * ODBC Data Provider
2
3 <ul>
4
5         <li>ADO.NET Data Provider for Data Sources 
6         that have <a href="http://www.microsoft.com/data/odbc/">ODBC</a> support.</li>
7
8         <li>Exists in namespace System.Data.Odbc and assembly System.Data</li>
9         
10         <li>Works on Windows and Linux. Should have no problems working on UNIX too.</li>
11         
12         <li>Works on Windows via the native Windows odbc32.dll</li>
13         
14         <li>Works on Linux via:
15         
16         <ul>
17                 <li><a href="http://www.unixodbc.org/">unixODBC</a> which has 
18                         commercial support 
19                         from <a href="http://www.easysoft.com/">Easysoft</a></li>
20                         
21                 <li><a href="http://www.iodbc.org/">iODBC</a> which has 
22                     commercial support 
23                     from <a href="http://oplweb.openlinksw.com:8080/download/">OpenLink Software</a></li>
24         </ul>
25         
26         <li>List of unixODBC <a href="http://www.unixodbc.org/drivers.html">drivers</a>
27         
28         <li>List of <a href="http://www.sqlsummit.com/odbcvend.htm">ODBC Vendors</a>
29         
30         <li>ODBC can connect to various databases which has an ODBC driver installed:
31         <ul> 
32                   <li><a href="http://www.mysql.com/">MySQL</a></li>
33                   <li><a href="http://www.postgresql.org/">PostgreSQL</a></li>
34                   <li><a href="http://www.oracle.com/">Oracle</a></li>
35                   <li><a href="http://www.borland.com/products/downloads/download_interbase.html">Interbase</a></li>
36                   <li><a href="http://www.sybase.com/downloads">Sybase</a> (
37                   via <a href="http://www.freetds.org/">FreeTDS</a> on UNIX)</li>
38                   <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a> (
39                   via <a href="http://www.freetds.org/">FreeTDS</a> on UNIX)</li>
40                   <li><a href="http://www-3.ibm.com/software/data/db2/">IBM DB2 Universal Database</a></li>
41                   <li><a href="http://www.microsoft.com/office/access">MS Access</a>
42                   (via <a href="http://mdbtools.sourceforge.net/">MDB Tools</a> on UNIX)</li>
43         </ul>
44                 
45         <li>ODBC Provider created by Brian Ritchie.</li>
46         
47         <li>Does not support trusted connections</li>
48         
49 </ul>
50         
51 ** Current Status
52
53 <ul>
54         <li>Can Connect on:
55         <ul>
56                 <li>Windows via native Windows odbc32.dll</a></li>
57                 <li>Linux via:
58                 <ul>
59                         <li>unixODBC's libodbc.so</li>
60                         <li>iODBC's libiodbc.so</li>
61                 </ul>
62                 </li>
63         </ul>
64         </li>
65         
66         <li>Various databases have been tested using their
67            ODBC drivers: MySQL, PostgreSQL, Oracle, IBM DB2, and Microsoft SQL Server</li>
68            
69         <li>Can execute non-query commands via ExecuteNonQuery of a OdbcCommand</li>
70         
71         <li>Can execute aggreates and retrieve a single row single column result via
72         ExecuteScalar of a OdbcCommand</li>
73         
74         <li>Can execute queries via ExecuteReader of a OdbcCommand and 
75         retrieve results using an OdbcDataReader</li>
76         
77         <li>Can get a DataTable containing schema info via GetSchemaTable() in a OdbcDataReader</li>
78         
79         <li>Can Fill a DataTable in a DataSet via an OdbcDataAdapter</li>
80         
81         <li>Works in SQL#, but Column names don't show up correctly.</li>
82         
83         <li>Bugs with Mono or the data provider should be reported 
84         in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>.  If you
85         do not have Bugzilla user account, it is free 
86         and easy to 
87         create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
88
89         
90 </ul>
91         
92 ** Action Plan
93
94 <ul>
95         
96         <li>Fixing bugs
97         
98         <li>Testing with other setups
99 </ul>
100
101 ** Testing ODBC provider with IBM DB2 Universal Database
102
103 <ul>
104         <li>You need a working mono and mcs</li>
105         
106         <li>For Unix, you will need unixODBC or iODBC installed</li>
107         
108         <li>Have acess to a <a href="http://www-306.ibm.com/software/data/db2/">IBM DB2 Universal Database</a> or
109         you can download from IBM</li>
110         
111         <li>Read these web pages about Unix, ODBC, and IBM DB2
112
113         <ul>
114                 <li><a href="http://www.unixodbc.com/doc/db2.html">unixODBC web page about IBM DB2</a></li>
115                 <li><a href="http://www-306.ibm.com/software/data/db2/udb/ad/v8/cli/t0010406.htm">IBM web page about unixODBC and DB2</a></li>
116         </ul>
117         </li>
118         
119         <li>The ODBC provider is similar to the <a href="http://www.go-mono.com/ibmdb2.html">IBM DB2</a> provider.</li>
120 </ul>
121
122 ** Testing ODBC provider with MySQL
123
124 <p>You can test Mono's ODBC provider System.Data.Odbc with the MySQL ODBC driver MyODBC
125         
126 <p><ul>
127         <li>Take a look at OdbcTest.cs in mcs/class/System.Data/Test</li>
128
129         <li>Here is a ConnectionString format if you have a DSN setup: 
130 <pre>
131 "DSN=dataSetName;UID=myuserid;PWD=mypassword"
132 </pre>
133         </li>
134         <li>Here is a ConnectionString format if you do not have a DSN (have not
135         gotten this to work though):
136 <pre>
137 "DRIVER={MySQL ODBC 3.51 Driver};" +\r
138 "SERVER=localhost;DATABASE=test;" +\r
139 "UID=myuserid;PASSWORD=mypassword;" +\r
140 "OPTION=3";\r
141
142 </pre>
143         </li>
144         <li>C# Example:
145 <pre>
146  using System;
147  using System.Data;
148  using System.Data.Odbc;
149  
150  public class Test 
151  {
152     public static void Main(string[] args)
153     {
154                 // have an ODBC DSN setup named MYSQLDSN
155                 // that accesses a MySQL database via
156                 // MyODBC driver for ODBC with a
157                 // hostname of localhost and database test
158        string connectionString = 
159           "DSN=MYSQLDSN;" +
160           "UID=myuserid;" +
161           "PWD=mypassword";
162        IDbConnection dbcon;
163        dbcon.Open();
164        dbcon = new OdbcConnection(connectionString);
165        IDbCommand dbcmd = dbcon.CreateCommand();
166        // requires a table to be created named employee
167        // with columns firstname and lastname
168        // such as,
169        //        CREATE TABLE employee (
170        //           firstname varchar(32),
171        //           lastname varchar(32));
172        string sql = 
173            "SELECT firstname, lastname " +
174            "FROM employee";
175        dbcmd.CommandText = sql;
176        IDataReader reader = dbcmd.ExecuteReader();
177        while(reader.Read()) {
178             string FirstName = (string) reader["firstname"];
179             string LastName = (string) reader["lastname"];
180             Console.WriteLine("Name: " + 
181                 FirstName + " " + LastName);
182        }
183        // clean up
184        reader.Close();
185        reader = null;
186        dbcmd.Dispose();
187        dbcmd = null;
188        dbcon.Close();
189        dbcon = null;
190     }
191  }
192 </pre>
193         </li>
194         <li>Building C# Example:
195         <ul>
196                 <li>Save the example to a file, such as, TestExample.cs</li>
197                 <li>Build on Linux:
198 <pre>
199         mcs TestExample.cs -r System.Data.dll
200 </pre>
201                 </li>
202                 <li>Build on Windows via Cygwin:
203 <pre>
204         mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
205              TestExample.cs \
206              -lib:C:/cygwin/home/MyHome/mono/install/lib \
207              -r System.Data.dll
208 </pre>
209                 </li>
210         </ul>
211         </li>
212         <li>Running the Example:
213 <pre>
214 mono TestExample.exe
215 </pre>
216         </li>
217         
218 </ul>