sqlclient 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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>Connect to Microsoft SQL Server 7/2000 databases via SQL Server authentication and NT Authentication.</li>
  21. <li>Connection pooling works.</li>
  22. <li>Stored Procedures work.</li>
  23. <li>Parameters work.</li>
  24. <li>Prepare works.</li>
  25. <li>SQL commands can be executed
  26. via ExecuteNonQuery() of a SqlCommand.</li>
  27. <li>SQL aggregates can be executed and a single row and single column
  28. result can be retrieved via ExecuteScalar() of a SqlCommand</li>
  29. <li>SQL queries can be executed via ExecuteReader() and results
  30. can be retrieved via SqlDataReader.</li>
  31. <li>a DataTable with schema info about a result can be gotten via GetSchemaTable()
  32. in a SqlDataReader</li>
  33. <li>XML can be read via ExecuteXmlReader in a SqlCommand.</li>
  34. <li>Data can be filled in a DataTable in a DataSet via a SqlDataAdapter</li>
  35. <li>Works in the SQL# command-line and GTK# GUI version</li>
  36. </ul>
  37. ** Action plan
  38. <ul>
  39. <li>Needs more testing and fixing bugs</li>
  40. <li>Start work on TDS Protocol Version 8.0 support</li>
  41. <li>Add support for the .NET Framework 2.0 (Whidbey)</li>
  42. <li>Add support for Microsoft SQL Server 2005 (Yukon) support</li>
  43. </ul>
  44. ** Testing
  45. <ul>
  46. <li>Have a working mono and mcs installed</li>
  47. <li>Have access to a Microsoft SQL Server database
  48. or either download it:
  49. <ul>
  50. <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a></li>
  51. </ul>
  52. </li>
  53. <li><b>IMPORTANT:</b> If using Microsoft SQL Server 2000, make sure
  54. you are using at least Service Pack 3 for Microsoft SQL Server 2000. If using
  55. MSDE 2000, make sure you have the special Service Pack 3 for MSDE 2000. You
  56. can get it from <a href="http://www.microsoft.com/sql/downloads/2000/sp3.asp">here</a></li>
  57. <li>For those that only have MSDE installed. You can change the authentication mode
  58. from Windows Only Authentication to SQL Server and Windows Authentications (also knows as Mixed-mode authentication)
  59. via the <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q322336&sd=tech#4">registry</a></li>. It is
  60. the LoginMode you need to change. By default,
  61. MSDE is installed with Windows Only Authentication. If you want SqlClient to work with MSDE via SQL Server authentication, you will
  62. need to change the setting. Otherwise, you wil have to use NT Authentication.</a>
  63. <li>If using MSDE, you might need to create a new user with password. Give
  64. this user access to various databases in this MSDE instance. Also, for each
  65. database, give this new user at least SELECT access to the various tables you want
  66. to retrieve data from.</li>
  67. <li>If you have Enterprise Manager, you can easily change the authentication mode
  68. for both MSDE and Microsoft SQL Server. To change the authentication mode in
  69. Enterprise Mananger, select the instance, right-click on it, and select properites.
  70. The SQL Server properties dialog for that instance will pop up. Choose the Security
  71. tab. Change the Authentication from Windows Only to SQL Server and Windows. If
  72. the instance of your database does not show up in Enterprise Manager, Register first
  73. by selecting the Action menu and choosing New SQL Server Registration.</li>
  74. <li>Located at mcs/class/System.Data/Test is a test for System.Data.SqlClient
  75. named SqlTest.cs and you could use this as a basis for your test.</li>
  76. <li>If you want to use Integrated Security (aka NT Authentication aka Trusted Connection aka Domain Login), you
  77. will need to specify the Domain User ID and Password. This is because Mono is not integrated with Windows
  78. nor SQL Server.</li>
  79. <li>Has a connection string format for SQL Server Authentication:
  80. <pre>
  81. Server=hostname;
  82. Database=databaseName;
  83. User ID=sqlServerUserid;
  84. Password=sqlServerPassword
  85. </pre>
  86. </li>
  87. <li>Has a connection string format for NT Authentication:
  88. <pre>
  89. Server=hostname;
  90. Database=databaseName;
  91. User ID=windowsDomain\windowsUserid;
  92. Password=windowsPassword;
  93. Integrated Security=SSPI
  94. </pre>
  95. </li>
  96. <li>The Server part can be used three ways:
  97. <table border=1>
  98. <tr>
  99. <td><b>Server Definition</b></td> <td><b>Example</b></td>
  100. </tr>
  101. <tr>
  102. <td>hostname</td> <td>Server=MYHOST</td>
  103. </tr>
  104. <tr>
  105. <td>hostname,port</td> <td>Server=MYHOST,1433</td>
  106. </tr>
  107. <tr>
  108. <td>hostname\instance</td> <td>Server=MYHOST\NETSDK</td>
  109. </tr>
  110. </table>
  111. </li>
  112. <li>C# Example using SQL Server Authentication:
  113. <pre>
  114. using System;
  115. using System.Data;
  116. using System.Data.SqlClient;
  117. public class Test
  118. {
  119. public static void Main(string[] args)
  120. {
  121. string connectionString =
  122. "Server=MyServer;" +
  123. "Database=pubs;" +
  124. "User ID=MySqlServerUserId;" +
  125. "Password=MySqlServerPassword;";
  126. IDbConnection dbcon;
  127. dbcon = new SqlConnection(connectionString);
  128. dbcon.Open();
  129. IDbCommand dbcmd = dbcon.CreateCommand();
  130. string sql =
  131. "SELECT fname, lname " +
  132. "FROM employee";
  133. dbcmd.CommandText = sql;
  134. IDataReader reader = dbcmd.ExecuteReader();
  135. while(reader.Read()) {
  136. string FirstName = (string) reader["fname"];
  137. string LastName = (string) reader["lname"];
  138. Console.WriteLine("Name: " +
  139. FirstName + " " + LastName);
  140. }
  141. // clean up
  142. reader.Close();
  143. reader = null;
  144. dbcmd.Dispose();
  145. dbcmd = null;
  146. dbcon.Close();
  147. dbcon = null;
  148. }
  149. }
  150. </pre>
  151. </li>
  152. <li>C# Example using NT Authentication (Integrated Security)
  153. <pre>
  154. using System;
  155. using System.Data;
  156. using System.Data.SqlClient;
  157. public class Test
  158. {
  159. public static void Main(string[] args)
  160. {
  161. string connectionString =
  162. "Server=MyServer;" +
  163. "Database=pubs;" +
  164. "User ID=MyWindowsDomain\\MyWindowsUserid;" +
  165. "Password=MyWindowsPassword;" +
  166. "Integrated Security=SSPI";
  167. IDbConnection dbcon;
  168. dbcon = new SqlConnection(connectionString);
  169. dbcon.Open();
  170. IDbCommand dbcmd = dbcon.CreateCommand();
  171. string sql =
  172. "SELECT fname, lname " +
  173. "FROM employee";
  174. dbcmd.CommandText = sql;
  175. IDataReader reader = dbcmd.ExecuteReader();
  176. while(reader.Read()) {
  177. string FirstName = (string) reader["fname"];
  178. string LastName = (string) reader["lname"];
  179. Console.WriteLine("Name: " +
  180. FirstName + " " + LastName);
  181. }
  182. // clean up
  183. reader.Close();
  184. reader = null;
  185. dbcmd.Dispose();
  186. dbcmd = null;
  187. dbcon.Close();
  188. dbcon = null;
  189. }
  190. }
  191. </pre>
  192. </li>
  193. <li>Building C# Example:
  194. <ul>
  195. <li>Save the example to a file, such as, TestExample.cs</li>
  196. <li>Build on Linux:
  197. <pre>
  198. mcs TestExample.cs -r System.Data.dll
  199. </pre>
  200. </li>
  201. </ul>
  202. </li>
  203. <li>Running the Example:
  204. <pre>
  205. mono TestExample.exe
  206. </pre>
  207. </li>
  208. </ul>