2 // System.Data.SqlClient.SqlException
\r
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace System.Data.SqlClient
\r
38 using System.Data.ProviderBase;
\r
41 * The exception that is thrown when SQL Server returns a warning or error.
\r
42 * This class cannot be inherited.
\r
46 * CURRENT LIMITATIONS
\r
47 * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc)
\r
49 * 2. Method "void GetObjectData(...,...)" is not supported (serialization)
\r
52 public sealed class SqlException : AbstractDbException
\r
54 internal SqlException(Exception cause, SqlConnection connection) : base(cause, connection) {}
\r
56 internal SqlException(SQLException cause, SqlConnection connection) : base(cause, connection) {}
\r
58 internal SqlException(string message, SQLException cause, SqlConnection connection) : base(message, cause, connection) {}
\r
60 protected override AbstractDbErrorCollection DbErrors {
\r
69 * Gets the severity level of the error returned from the SQL Server .NET
\r
71 * @return severity level of the first error in the collection.
\r
77 SqlErrorCollection errors = Errors;
\r
78 return errors.Count > 0 ? errors[0].Class : (byte)0;
\r
83 * Gets a collection of one or more SqlError objects that give detailed
\r
84 * information about exceptions generated by the SQL Server .NET Data Provider.
\r
85 * @return collection of SqlError objects
\r
87 public SqlErrorCollection Errors
\r
91 return new SqlErrorCollection(_cause, _connection);
\r
96 * Gets the line number within the Transact-SQL command batch or stored
\r
97 * procedure that generated the error.
\r
98 * @return line number of the first error in the collection.
\r
100 public int LineNumber
\r
104 SqlErrorCollection errors = Errors;
\r
105 return errors.Count > 0 ? errors[0].LineNumber : 0;
\r
110 * Gets a number that identifies the type of error.
\r
111 * @return number that identifies the type of first error in the collection
\r
117 SqlErrorCollection errors = Errors;
\r
118 return errors.Count > 0 ? errors[0].Number : 0;
\r
123 * Gets the name of the stored procedure or remote procedure call (RPC)
\r
124 * that generated the error.
\r
125 * @return name of the stored procedure
\r
127 public String Procedure
\r
131 SqlErrorCollection errors = Errors;
\r
132 return errors.Count > 0 ? errors[0].Procedure : null;
\r
137 * Gets the name of the computer running an instance of SQL Server
\r
138 * that generated the error.
\r
139 * @return name of the computer where error generated
\r
141 public String Server
\r
145 SqlErrorCollection errors = Errors;
\r
146 return errors.Count > 0 ? errors[0].Server : null;
\r
152 * Gets a numeric error code from SQL Server that represents an error,
\r
153 * warning or "no data found" message.
\r
154 * @return numeric error code from SQL Server
\r
160 SqlErrorCollection errors = Errors;
\r
161 return errors.Count > 0 ? errors[0].State : (byte)0;
\r