odbc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. * ODBC Data Provider
  2. <ul>
  3. <li>ADO.NET Data Provider for Data Sources
  4. that have <a href="http://www.microsoft.com/data/odbc/">ODBC</a> support.</li>
  5. <li>Exists in namespace System.Data.Odbc and assembly System.Data</li>
  6. <li>Works on Windows and Linux. Should have no problems working on UNIX too.</li>
  7. <li>Works on Windows via the native Windows odbc32.dll</li>
  8. <li>Works on Linux via:
  9. <ul>
  10. <li><a href="http://www.unixodbc.org/">unixODBC</a> which has
  11. commercial support
  12. from <a href="http://www.easysoft.com/">Easysoft</a></li>
  13. <li><a href="http://www.iodbc.org/">iODBC</a> which has
  14. commercial support
  15. from <a href="http://oplweb.openlinksw.com:8080/download/">OpenLink Software</a></li>
  16. </ul>
  17. <li>List of unixODBC <a href="http://www.unixodbc.org/drivers.html">drivers</a>
  18. <li>List of <a href="http://ourworld.compuserve.com/homepages/Ken_North/odbcvend.htm">ODBC Vendors</a>
  19. <li>ODBC can connect to various databases which has an ODBC driver installed:
  20. <ul>
  21. <li><a href="http://www.mysql.com/">MySQL</a></li>
  22. <li><a href="http://www.postgresql.org/">PostgreSQL</a></li>
  23. <li><a href="http://www.oracle.com/">Oracle</a></li>
  24. <li><a href="http://www.borland.com/products/downloads/download_interbase.html">Interbase</a></li>
  25. <li><a href="http://www.sybase.com/downloads">Sybase</a> (
  26. via <a href="http://www.freetds.org/">FreeTDS</a> on UNIX)</li>
  27. <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a> (
  28. via <a href="http://www.freetds.org/">FreeTDS</a> on UNIX)</li>
  29. <li><a href="http://www-3.ibm.com/software/data/db2/">IBM DB2 Universal Database</a></li>
  30. <li><a href="http://www.microsoft.com/office/access/default.asp">MS Access</a>
  31. (via <a href="http://mdbtools.sourceforge.net/">MDB Tools</a> on UNIX)</li>
  32. </ul>
  33. <li>ODBC Provider created by Brian Ritchie.</li>
  34. <li>Does not support trusted connections</li>
  35. </ul>
  36. ** Current Status
  37. <ul>
  38. <li>Can Connect on:
  39. <ul>
  40. <li>Windows via native Windows odbc32.dll</a></li>
  41. <li>Linux via:
  42. <ul>
  43. <li>unixODBC's libodbc.so</li>
  44. <li>iODBC's libiodbc.so</li>
  45. </ul>
  46. </li>
  47. </ul>
  48. </li>
  49. <li>Various databases have been tested using their
  50. ODBC drivers: MySQL, PostgreSQL, Oracle, IBM DB2, and Microsoft SQL Server</li>
  51. <li>Can execute non-query commands via ExecuteNonQuery of a OdbcCommand</li>
  52. <li>Can execute aggreates and retrieve a single row single column result via
  53. ExecuteScalar of a OdbcCommand</li>
  54. <li>Can execute queries via ExecuteReader of a OdbcCommand and
  55. retrieve results using an OdbcDataReader</li>
  56. <li>Can get a DataTable containing schema info via GetSchemaTable() in a OdbcDataReader</li>
  57. <li>Can Fill a DataTable in a DataSet via an OdbcDataAdapter</li>
  58. <li>Works in SQL#, but Column names don't show up correctly.</li>
  59. <li>Bugs with Mono or the data provider should be reported
  60. in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>. If you
  61. do not have Bugzilla user account, it is free
  62. and easy to
  63. create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
  64. </ul>
  65. ** Action Plan
  66. <ul>
  67. <li>Fixing bugs
  68. <li>Testing with other setups
  69. </ul>
  70. ** Testing ODBC provider with IBM DB2 Universal Database
  71. <ul>
  72. <li>You need a working mono and mcs</li>
  73. <li>For Unix, you will need unixODBC or iODBC installed</li>
  74. <li>Have acess to a <a href="http://www-3.ibm.com/software/data/db2/">IBM DB2 Universal Database</a> or
  75. you can download from IBM</li>
  76. <li>Read these web pages about Unix, ODBC, and IBM DB2
  77. <ul>
  78. <li><a href="http://www.unixodbc.com/doc/db2.html">unixODBC web page about IBM DB2</a></li>
  79. <li><a href="http://www-3.ibm.com/software/data/db2/udb/ad/v8/cli/t0010406">IBM web page about unixODBC and DB2</a></li>
  80. </ul>
  81. </li>
  82. <li>The ODBC provider is similar to the <a href="http://www.go-mono.com/ibmdb2.html">IBM DB2</a> provider.</li>
  83. </ul>
  84. ** Testing ODBC provider with MySQL
  85. <p>You can test Mono's ODBC provider System.Data.Odbc with the MySQL ODBC driver MyODBC
  86. <p><ul>
  87. <li>Take a look at OdbcTest.cs in mcs/class/System.Data/Test</li>
  88. <li>Here is a ConnectionString format if you have a DSN setup:
  89. <pre>
  90. "DSN=dataSetName;UID=myuserid;PWD=mypassword"
  91. </pre>
  92. </li>
  93. <li>Here is a ConnectionString format if you do not have a DSN (have not
  94. gotten this to work though):
  95. <pre>
  96. "DRIVER={MySQL ODBC 3.51 Driver};" +
  97. "SERVER=localhost;DATABASE=test;" +
  98. "UID=myuserid;PASSWORD=mypassword;" +
  99. "OPTION=3";
  100. </pre>
  101. </li>
  102. <li>C# Example:
  103. <pre>
  104. using System;
  105. using System.Data;
  106. using System.Data.Odbc;
  107. public class Test
  108. {
  109. public static void Main(string[] args)
  110. {
  111. // have an ODBC DSN setup named MYSQLDSN
  112. // that accesses a MySQL database via
  113. // MyODBC driver for ODBC with a
  114. // hostname of localhost and database test
  115. string connectionString =
  116. "DSN=MYSQLDSN;" +
  117. "UID=myuserid;" +
  118. "PWD=mypassword";
  119. IDbConnection dbcon;
  120. dbcon.Open();
  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.CommandText = sql;
  133. IDataReader reader = dbcmd.ExecuteReader();
  134. while(reader.Read()) {
  135. string FirstName = (string) reader["firstname"];
  136. string LastName = (string) 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. </ul>