3 <li>Exists in namespace System.Data.Odbc and assembly System.Data
5 <li>Works on Windows and Linux. Should have no problems working on UNIX too.
7 <li>Works on Windows via the native Windows odbc32.dll
9 <li>Works on Linux via:
12 <li><a href="http://www.unixodbc.org/">unixODBC</a> which has
14 from <a href="http://www.easysoft.com/">Easysoft</a></li>
16 <li><a href="http://www.iodbc.org/">iODBC</a> which has
18 from <a href="http://oplweb.openlinksw.com:8080/download/">OpenLink Software</a></li>
21 <li>List of unixODBC <a href="http://www.unixodbc.org/drivers.html">drivers</a>
23 <li>List of <a href="http://ourworld.compuserve.com/homepages/Ken_North/odbcvend.htm">ODBC Vendors</a>
25 <li>ODBC can connect to various databases which has an ODBC driver installed:
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)
39 <li>ODBC Provider created by Brian Ritchie.</li>
41 <li>Does not support trusted connections</li>
49 <li>Windows via native Windows odbc32.dll</a></li>
52 <li>unixODBC's libodbc.so</li>
53 <li>iODBC's libiodbc.so</li>
59 <li>Various databases have been tested using their
60 ODBC drivers: MySQL, PostgreSQL, Oracle, IBM DB2, and Microsoft SQL Server</li>
62 <li>Can execute non-query commands via ExecuteNonQuery of a OdbcCommand</li>
64 <li>Can execute aggreates and retrieve a single row single column result via
65 ExecuteScalar of a OdbcCommand</li>
67 <li>Can execute queries via ExecuteReader of a OdbcCommand and
68 retrieve results using an OdbcDataReader</li>
70 <li>Can get a DataTable containing schema info via GetSchemaTable() in a OdbcDataReader</li>
72 <li>Can Fill a DataTable in a DataSet via an OdbcDataAdapter</li>
81 <li>Testing with other setups
84 ** Testing ODBC provider
86 <p>Test Mono's ODBC provider System.Data.Odbc with the MySQL ODBC driver MyODBC
89 <li>Take a look at OdbcTest.cs in mcs/class/System.Data/Test</li>
91 <li>Here is a ConnectionString format if you have a DSN setup:
93 "DSN=dataSetName;UID=username;PWD=password"
96 <li>Here is a ConnectionString format if you do not have DSN (have not
99 "DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=;DATABASE=pubs"
106 using System.Data.Odbc;
110 public static void Main(string[] args)
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 =
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
126 // CREATE TABLE employee (
127 // firstname varchar(32),
128 // lastname varchar(32));
130 "SELECT firstname, lastname " +
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);
151 <li>Building C# Example:
153 <li>Save the example to a file, such as, TestExample.cs</li>
156 mcs TestExample.cs -r System.Data.dll
159 <li>Build on Windows via Cygwin:
161 mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
163 -lib:C:/cygwin/home/MyHome/mono/install/lib \
169 <li>Running the Example: