2 // System.Data.SqlClient.SqlException.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
12 using System.Runtime.Serialization;
14 namespace System.Data.SqlClient
17 /// Exceptions, as returned by SQL databases.
19 public sealed class SqlException : SystemException
21 private SqlErrorCollection errors;
23 internal SqlException()
24 : base("a SQL Exception has occurred") {
25 errors = new SqlErrorCollection();
28 internal SqlException(byte theClass, int lineNumber,
29 string message, int number, string procedure,
30 string server, string source, byte state)
33 errors = new SqlErrorCollection (theClass,
36 server, source, state);
45 return 0; // FIXME: throw exception here?
47 return errors[0].Class;
51 errors[0].SetClass(value);
56 public SqlErrorCollection Errors {
67 public int LineNumber {
70 return 0; // FIXME: throw exception here?
71 return errors[0].LineNumber;
75 errors[0].SetLineNumber(value);
80 public override string Message {
83 return ""; // FIXME: throw exception?
88 for(i = 0; i < errors.Count - 1; i++) {
89 msg = msg + errors[i].Message + "\n";
91 msg = msg + errors[i].Message;
101 if(errors.Count == 0)
102 return 0; // FIXME: throw exception?
104 return errors[0].Number;
108 errors[0].SetNumber(value);
113 public string Procedure {
115 if(errors.Count == 0)
116 return ""; // FIXME: throw exception?
118 return errors[0].Procedure;
122 errors[0].SetProcedure(value);
127 public string Server {
129 if(errors.Count == 0)
130 return ""; // FIXME: throw exception?
132 return errors[0].Server;
136 errors[0].SetServer(value);
141 public override string Source {
143 if(errors.Count == 0)
144 return ""; // FIXME: throw exception?
146 return errors[0].Source;
150 errors[0].SetSource(value);
157 if(errors.Count == 0)
158 return 0; // FIXME: throw exception?
160 return errors[0].State;
164 errors[0].SetState(value);
168 #endregion // Properties
173 public override void GetObjectData(SerializationInfo si,
174 StreamingContext context) {
179 // [ClassInterface(ClassInterfaceType.AutoDual)]
180 public override string ToString() {
182 for (int i = 0; i < errors.Count; i++) {
183 toStr = toStr + errors[i].ToString() + "\n";
188 internal void Add(byte theClass, int lineNumber,
189 string message, int number, string procedure,
190 string server, string source, byte state) {
192 errors.Add (theClass, lineNumber, message,
194 server, source, state);
199 // FIXME: destructor to release resources
202 #endregion // Methods