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