sqlclient 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. * Microsoft SQL Server Provider
  2. <ul>
  3. <li>ADO.NET Provider for Microsoft SQL Server 7/2000 databases</li>
  4. <li>Exists in namespace System.Data.SqlClient and assembly System.Data</li>
  5. <li>Created by Tim Coleman</li>
  6. <li>Used the <a href="http://www.freetds.org/">FreeTDS</a> and
  7. <a href="http://jtds.sourceforge.net/">jTDS</a> projects as resources.</li>
  8. <li>Implemented in 100% C#</li>
  9. <li>Is similar to the Mono.Data.TdsClient and Mono.Data.SybaseClient providers.</li>
  10. <li>Requires the assembly Mono.Data.Tds.dll which implements the TDS protocol in 100% C#.</li>
  11. <li>Uses TDS Protocol Version 7.0</li>
  12. <li>Bugs with Mono or the data provider should be reported
  13. in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>. If you
  14. do not have Bugzilla user account, it is free
  15. and easy to
  16. create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
  17. </ul>
  18. ** Current Status
  19. <ul>
  20. <li>Thanks to Sebastien Pouliot, we now have NT Authentication (Integrated Security) support. This support was
  21. added after the release of Mono 0.29. So, you either get it from cvs or wait for the Mono 0.30 release.</li>
  22. <li>Able to connect to Microsoft SQL Server 7/2000 databases via SQL Server authentication and NT Authentication.</li>
  23. <li>Connection pooling works.</li>
  24. <li>Stored Procedures work.</li>
  25. <li>Parameters work.</li>
  26. <li>Prepare works.</li>
  27. <li>SQL commands can be executed
  28. via ExecuteNonQuery() of a SqlCommand.</li>
  29. <li>SQL aggregates can be executed and a single row and single column
  30. result can be retrieved via ExecuteScalar() of a SqlCommand</li>
  31. <li>SQL queries can be executed via ExecuteReader() and results
  32. can be retrieved via SqlDataReader.</li>
  33. <li>a DataTable with schema info about a result can be gotten via GetSchemaTable()
  34. in a SqlDataReader</li>
  35. <li>XML can be read via ExecuteXmlReader in a SqlCommand.</li>
  36. <li>Data can be filled in a DataTable in a DataSet via a SqlDataAdapter</li>
  37. <li>Uses TDS Protocol Version 7.0</li>
  38. <li>Works in the SQL# command-line and GTK# GUI version</li>
  39. </ul>
  40. ** Action plan
  41. <ul>
  42. <li>Connection timeouts is being developed now</li>
  43. <li>Needs more testing</li>
  44. <li>Start work on TDS Protocol Version 8.0 support</li>
  45. <li>Add support for .NET 1.2 and 2.0 and Microsoft SQL Server (Yukon) support</li>
  46. </ul>
  47. ** Testing
  48. <ul>
  49. <li>Have a working mono and mcs installed</li>
  50. <li>Have access to a Microsoft SQL Server database
  51. or either download it:
  52. <ul>
  53. <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a></li>
  54. </ul>
  55. </li>
  56. <li><b>IMPORTANT:</b> If using Microsoft SQL Server 2000, make sure
  57. you are using at least Service Pack 3 for Microsoft SQL Server 2000. If using
  58. MSDE 2000, make sure you have the special Service Pack 3 for MSDE 2000. You
  59. can get it from <a href="http://www.microsoft.com/sql/downloads/2000/sp3.asp">here</a></li>
  60. <li>For those that only have MSDE installed. You can change the authentication mode
  61. from Windows Only Authentication to SQL Server and Windows Authentications (also knows as Mixed-mode authentication)
  62. via the <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q322336&sd=tech#4">registry</a></li>. It is
  63. the LoginMode you need to change. By default,
  64. MSDE is installed with Windows Only Authentication. For SqlClient to work with MSDE, you will
  65. need to change the setting.</a>
  66. <li>If using MSDE, you might need to create a new user with password. Give
  67. this user access to various databases in this MSDE instance. Also, for each
  68. database, give this new user at least SELECT access to the various tables you want
  69. to retrieve data from.</li>
  70. <li>If you have Enterprise Manager, you can easily change the authentication mode
  71. for both MSDE and Microsoft SQL Server. To change the authentication mode in
  72. Enterprise Mananger, select the instance, right-click on it, and select properites.
  73. The SQL Server properties dialog for that instance will pop up. Choose the Security
  74. tab. Change the authentication from Windows Only to SQL Server and Windows. If
  75. the instance of your database does not show up in Enterprise Manager, Register first
  76. by selecting the Action menu and choosing New SQL Server Registration.</li>
  77. <li>Located at mcs/class/System.Data/Test is a test for System.Data.SqlClient
  78. named SqlTest.cs and you could use this as a basis for your test.</li>
  79. <li>Mono's SqlClient does not support trusted connections
  80. nor integrated security. You can not use this when connecting. You need
  81. to explicitly use a User ID and Password
  82. authenticated by SQL Server.</li>
  83. <li>Has a connection string format for SQL Server Authentication:
  84. <pre>
  85. Server=hostname;Database=databaseName;User ID=userid;Password=password
  86. </pre>
  87. </li>
  88. <li>Has a connection string format for NT Authentication:
  89. <pre>
  90. Server=hostname;Database=databaseName;User ID=windowsUserid;Password=windowsPassword;Integrated Security=SSPI
  91. </pre>
  92. </li>
  93. <li>The Server part can be used three ways:
  94. <table border=1>
  95. <tr>
  96. <td><b>Server Definition</b></td> <td><b>Example</b></td>
  97. </tr>
  98. <tr>
  99. <td>hostname</td> <td>Server=MYHOST</td>
  100. </tr>
  101. <tr>
  102. <td>hostname,port</td> <td>Server=MYHOST,1433</td>
  103. </tr>
  104. <tr>
  105. <td>hostname\\instance</td> <td>Server=MYHOST\\NETSDK</td>
  106. </tr>
  107. </table>
  108. </li>
  109. <li>C# Example:
  110. <pre>
  111. using System;
  112. using System.Data;
  113. using System.Data.SqlClient;
  114. public class Test
  115. {
  116. public static void Main(string[] args)
  117. {
  118. string connectionString =
  119. "Server=localhost;" +
  120. "Database=pubs;" +
  121. "User ID=myuserid;" +
  122. "Password=mypassword;";
  123. IDbConnection dbcon;
  124. dbcon = new SqlConnection(connectionString);
  125. dbcon.Open();
  126. IDbCommand dbcmd = dbcon.CreateCommand();
  127. string sql =
  128. "SELECT fname, lname " +
  129. "FROM employee";
  130. dbcmd.CommandText = sql;
  131. IDataReader reader = dbcmd.ExecuteReader();
  132. while(reader.Read()) {
  133. string FirstName = (string) reader["fname"];
  134. string LastName = (string) reader["lname"];
  135. Console.WriteLine("Name: " +
  136. FirstName + " " + LastName);
  137. }
  138. // clean up
  139. reader.Close();
  140. reader = null;
  141. dbcmd.Dispose();
  142. dbcmd = null;
  143. dbcon.Close();
  144. dbcon = null;
  145. }
  146. }
  147. </pre>
  148. </li>
  149. <li>Building C# Example:
  150. <ul>
  151. <li>Save the example to a file, such as, TestExample.cs</li>
  152. <li>Build on Linux:
  153. <pre>
  154. mcs TestExample.cs -r System.Data.dll
  155. </pre>
  156. </li>
  157. <li>Build on Windows via Cygwin:
  158. <pre>
  159. mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
  160. TestExample.cs -r System.Data.dll
  161. </pre>
  162. </li>
  163. </ul>
  164. </li>
  165. <li>Running the Example:
  166. <pre>
  167. mono TestExample.exe
  168. </pre>
  169. </li>
  170. </ul>