SqlException.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // System.Data.SqlClient.SqlException.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. //
  9. // (C) Ximian, Inc
  10. // Copyright (C) Tim Coleman, 2002
  11. //
  12. using Mono.Data.Tds.Protocol;
  13. using System;
  14. using System.ComponentModel;
  15. using System.Data;
  16. using System.Runtime.Serialization;
  17. using System.Text;
  18. namespace System.Data.SqlClient {
  19. [Serializable]
  20. public sealed class SqlException : SystemException
  21. {
  22. #region Fields
  23. SqlErrorCollection errors;
  24. #endregion // Fields
  25. #region Constructors
  26. internal SqlException ()
  27. : base ("a SQL Exception has occurred.")
  28. {
  29. errors = new SqlErrorCollection();
  30. }
  31. internal SqlException (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state)
  32. : base (message)
  33. {
  34. errors = new SqlErrorCollection (theClass, lineNumber, message, number, procedure, server, source, state);
  35. }
  36. #endregion // Constructors
  37. #region Properties
  38. public byte Class {
  39. get { return Errors [0].Class; }
  40. }
  41. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  42. public SqlErrorCollection Errors {
  43. get { return errors; }
  44. }
  45. public int LineNumber {
  46. get { return Errors [0].LineNumber; }
  47. }
  48. public override string Message {
  49. get {
  50. StringBuilder result = new StringBuilder ();
  51. foreach (SqlError error in Errors) {
  52. if (result.Length > 0)
  53. result.Append ('\n');
  54. result.Append (error.Message);
  55. }
  56. return result.ToString ();
  57. }
  58. }
  59. public int Number {
  60. get { return Errors [0].Number; }
  61. }
  62. public string Procedure {
  63. get { return Errors [0].Procedure; }
  64. }
  65. public string Server {
  66. get { return Errors [0].Server; }
  67. }
  68. public override string Source {
  69. get { return Errors [0].Source; }
  70. }
  71. public byte State {
  72. get { return Errors [0].State; }
  73. }
  74. #endregion // Properties
  75. #region Methods
  76. internal static SqlException FromTdsInternalException (TdsInternalException e)
  77. {
  78. return new SqlException (e.Class, e.LineNumber, e.Message, e.Number, e.Procedure, e.Server, "Mono SqlClient Data Provider", e.State);
  79. }
  80. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  81. {
  82. if (si == null)
  83. throw new ArgumentNullException ("si");
  84. si.AddValue ("errors", errors);
  85. base.GetObjectData (si, context);
  86. }
  87. #endregion // Methods
  88. }
  89. }