2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / web / sqlclient
1 * Microsoft SQL Server Provider
2
3 <ul>
4         <li>ADO.NET Provider for Microsoft SQL Server 7/2000 databases</li>
5
6         <li>Exists in namespace System.Data.SqlClient and assembly System.Data</li>
7         
8         <li>Created by Tim Coleman</li>
9         
10         <li>Used the <a href="http://www.freetds.org/">FreeTDS</a> and 
11         <a href="http://jtds.sourceforge.net/">jTDS</a> projects as resources.</li>
12         
13         <li>Implemented in 100% C#</li>
14         
15         <li>Is similar to the Mono.Data.TdsClient and Mono.Data.SybaseClient providers.</li>
16         
17         <li>Requires the assembly Mono.Data.Tds.dll which implements the TDS protocol in 100% C#.</li>
18         
19         <li>Uses TDS Protocol Version 7.0</li>
20         
21         <li>Bugs with Mono or the data provider should be reported 
22         in Mono's Bugzilla <a href="http://bugzilla.ximian.com/">here</a>.  If you
23         do not have Bugzilla user account, it is free 
24         and easy to 
25         create one <a href="http://bugzilla.ximian.com/createaccount.cgi">here</a>.</li>
26         
27 </ul>
28
29
30 ** Current Status
31
32
33 <ul>
34
35         <li>Connect to Microsoft SQL Server 7/2000 databases via SQL Server authentication and NT Authentication.</li>
36         
37         <li>Connection pooling works.</li>
38         
39         <li>Stored Procedures work.</li>
40         
41         <li>Parameters work.</li>
42         
43         <li>Prepare works.</li>
44         
45         <li>SQL commands can be executed
46         via ExecuteNonQuery() of a SqlCommand.</li>
47         
48         <li>SQL aggregates can be executed and a single row and single column
49         result can be retrieved via ExecuteScalar() of a SqlCommand</li>
50         
51         <li>SQL queries can be executed via ExecuteReader() and results 
52         can be retrieved via SqlDataReader.</li>
53         
54         <li>a DataTable with schema info about a result can be gotten via GetSchemaTable()
55         in a SqlDataReader</li>
56         
57         <li>XML can be read via ExecuteXmlReader in a SqlCommand.</li>
58         
59         <li>Data can be filled in a DataTable in a DataSet via a SqlDataAdapter</li>
60         
61         <li>Works in the SQL# command-line and GTK# GUI version</li>
62 </ul>
63
64 ** Action plan
65
66 <ul>
67         
68         <li>Needs more testing and fixing bugs</li>
69         
70         <li>Start work on TDS Protocol Version 8.0 support</li>
71         
72         <li>Add support for the .NET Framework 2.0 (Whidbey)</li>
73         
74         <li>Add support for Microsoft SQL Server 2005 (Yukon) support</li>
75
76 </ul>
77
78 ** Testing
79
80 <ul>
81         <li>Have a working mono and mcs installed</li>
82         
83         <li>Have access to a Microsoft SQL Server database 
84         or either download it:
85                 <ul>
86                         <li><a href="http://www.microsoft.com/sql/default.asp">Microsoft SQL Server</a></li>
87                 </ul>
88         </li>
89         
90         <li><b>IMPORTANT:</b> If using Microsoft SQL Server 2000, make sure
91         you are using at least Service Pack 3 for Microsoft SQL Server 2000.  If using
92         MSDE 2000, make sure you have the special Service Pack 3 for MSDE 2000.  You
93         can get it from <a href="http://www.microsoft.com/sql/downloads/2000/sp3.asp">here</a></li>
94         
95         <li>For those that only have MSDE installed.  You can change the authentication mode \r
96         from Windows Only Authentication to SQL Server and Windows Authentications (also knows as Mixed-mode authentication)\r
97         via the <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q322336&sd=tech#4">registry</a></li>.  It is\r
98         the LoginMode you need to change.  By default,\r
99         MSDE is installed with Windows Only Authentication. If you want SqlClient to work with MSDE via SQL Server authentication, you will\r
100         need to change the setting. Otherwise, you wil have to use NT Authentication.</a>\r
101         \r
102         <li>If using MSDE, you might need to create a new user with password.  Give\r
103     this user access to various databases in this MSDE instance.  Also, for each\r
104     database, give this new user at least SELECT access to the various tables you want\r
105     to retrieve data from.</li>\r
106         \r
107         <li>If you have Enterprise Manager, you can easily change the authentication mode\r
108         for both MSDE and Microsoft SQL Server.  To change the authentication mode in \r
109         Enterprise Mananger, select the instance, right-click on it, and select properites.\r
110         The SQL Server properties dialog for that instance will pop up.  Choose the Security\r
111         tab.  Change the Authentication from Windows Only to SQL Server and Windows.  If\r
112         the instance of your database does not show up in Enterprise Manager, Register first\r
113         by selecting the Action menu and choosing New SQL Server Registration.</li>\r
114
115         <li>Located at mcs/class/System.Data/Test is a test for System.Data.SqlClient
116         named SqlTest.cs and you could use this as a basis for your test.</li>
117         
118         <li>If you want to use Integrated Security (aka NT Authentication aka Trusted Connection aka Domain Login), you
119         will need to specify the Domain User ID and Password.  This is because Mono is not integrated with Windows
120         nor SQL Server.</li>
121         
122         <li>Has a connection string format for SQL Server Authentication:
123 <pre>
124  Server=hostname;
125  Database=databaseName;
126  User ID=sqlServerUserid;
127  Password=sqlServerPassword
128 </pre>
129         </li>
130         <li>Has a connection string format for NT Authentication:
131 <pre>
132  Server=hostname;
133  Database=databaseName;
134  User ID=windowsDomain\windowsUserid;
135  Password=windowsPassword;
136  Integrated Security=SSPI
137 </pre>
138         </li>
139
140         <li>The Server part can be used three ways:
141         
142                 <table border=1>
143                         <tr>
144                                 <td><b>Server Definition</b></td> <td><b>Example</b></td>
145                         </tr>   
146                 
147                         <tr>
148                                 <td>hostname</td> <td>Server=MYHOST</td>
149                         </tr>
150                         
151                         <tr>
152                                 <td>hostname,port</td> <td>Server=MYHOST,1433</td>
153                         </tr>
154                         
155                         <tr>
156                                 <td>hostname\instance</td> <td>Server=MYHOST\NETSDK</td>
157                         </tr>
158                 </table>
159         </li>
160         
161         <li>C# Example using SQL Server Authentication:
162 <pre>
163  using System;
164  using System.Data;
165  using System.Data.SqlClient;
166  
167  public class Test 
168  {
169     public static void Main(string[] args)
170     {
171        string connectionString = 
172           "Server=MyServer;" +
173           "Database=pubs;" +
174           "User ID=MySqlServerUserId;" +
175           "Password=MySqlServerPassword;";
176        IDbConnection dbcon;
177        dbcon = new SqlConnection(connectionString);
178        dbcon.Open();
179        IDbCommand dbcmd = dbcon.CreateCommand();
180        string sql = 
181            "SELECT fname, lname " +
182            "FROM employee";
183        dbcmd.CommandText = sql;
184        IDataReader reader = dbcmd.ExecuteReader();
185        while(reader.Read()) {
186             string FirstName = (string) reader["fname"];
187             string LastName = (string) reader["lname"];
188             Console.WriteLine("Name: " + 
189                  FirstName + " " + LastName);
190        }
191        // clean up
192        reader.Close();
193        reader = null;
194        dbcmd.Dispose();
195        dbcmd = null;
196        dbcon.Close();
197        dbcon = null;
198     }
199  }
200 </pre>
201         </li>
202
203         <li>C# Example using NT Authentication (Integrated Security)
204 <pre>
205  using System;
206  using System.Data;
207  using System.Data.SqlClient;
208  
209  public class Test 
210  {
211     public static void Main(string[] args)
212     {
213        string connectionString = 
214           "Server=MyServer;" +
215           "Database=pubs;" +
216           "User ID=MyWindowsDomain\\MyWindowsUserid;" +
217           "Password=MyWindowsPassword;" +
218           "Integrated Security=SSPI";
219        IDbConnection dbcon;
220        dbcon = new SqlConnection(connectionString);
221        dbcon.Open();
222        IDbCommand dbcmd = dbcon.CreateCommand();
223        string sql = 
224            "SELECT fname, lname " +
225            "FROM employee";
226        dbcmd.CommandText = sql;
227        IDataReader reader = dbcmd.ExecuteReader();
228        while(reader.Read()) {
229             string FirstName = (string) reader["fname"];
230             string LastName = (string) reader["lname"];
231             Console.WriteLine("Name: " + 
232                  FirstName + " " + LastName);
233        }
234        // clean up
235        reader.Close();
236        reader = null;
237        dbcmd.Dispose();
238        dbcmd = null;
239        dbcon.Close();
240        dbcon = null;
241     }
242  }
243 </pre>
244         </li>
245
246         <li>Building C# Example:
247         <ul>
248                 <li>Save the example to a file, such as, TestExample.cs</li>
249                 <li>Build on Linux:
250 <pre>
251         mcs TestExample.cs -r System.Data.dll
252 </pre>
253                 </li>
254         </ul>
255         </li>
256         <li>Running the Example:
257 <pre>
258 mono TestExample.exe
259 </pre>
260         </li>
261
262 </ul>
263