SqlException.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // System.Data.SqlClient.SqlException
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. // Boris Kirzner <[email protected]>
  7. //
  8. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. namespace System.Data.SqlClient
  31. {
  32. using java.sql;
  33. using System;
  34. using System.Data.ProviderBase;
  35. /**
  36. * The exception that is thrown when SQL Server returns a warning or error.
  37. * This class cannot be inherited.
  38. */
  39. /*
  40. * CURRENT LIMITATIONS
  41. * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc)
  42. * is not supported.
  43. * 2. Method "void GetObjectData(...,...)" is not supported (serialization)
  44. */
  45. public sealed class SqlException : AbstractDbException
  46. {
  47. internal SqlException(Exception cause, SqlConnection connection) : base(cause, connection) {}
  48. internal SqlException(SQLException cause, SqlConnection connection) : base(cause, connection) {}
  49. internal SqlException(string message, SQLException cause, SqlConnection connection) : base(message, cause, connection) {}
  50. protected override AbstractDbErrorCollection DbErrors {
  51. get {
  52. return Errors;
  53. }
  54. }
  55. /**
  56. * Gets the severity level of the error returned from the SQL Server .NET
  57. * Data Provider.
  58. * @return severity level of the first error in the collection.
  59. */
  60. public byte Class
  61. {
  62. get
  63. {
  64. SqlErrorCollection errors = Errors;
  65. return errors.Count > 0 ? errors[0].Class : (byte)0;
  66. }
  67. }
  68. /**
  69. * Gets a collection of one or more SqlError objects that give detailed
  70. * information about exceptions generated by the SQL Server .NET Data Provider.
  71. * @return collection of SqlError objects
  72. */
  73. public SqlErrorCollection Errors
  74. {
  75. get
  76. {
  77. return new SqlErrorCollection(_cause, _connection);
  78. }
  79. }
  80. /**
  81. * Gets the line number within the Transact-SQL command batch or stored
  82. * procedure that generated the error.
  83. * @return line number of the first error in the collection.
  84. */
  85. public int LineNumber
  86. {
  87. get
  88. {
  89. SqlErrorCollection errors = Errors;
  90. return errors.Count > 0 ? errors[0].LineNumber : 0;
  91. }
  92. }
  93. /**
  94. * Gets a number that identifies the type of error.
  95. * @return number that identifies the type of first error in the collection
  96. */
  97. public int Number
  98. {
  99. get
  100. {
  101. SqlErrorCollection errors = Errors;
  102. return errors.Count > 0 ? errors[0].Number : 0;
  103. }
  104. }
  105. /**
  106. * Gets the name of the stored procedure or remote procedure call (RPC)
  107. * that generated the error.
  108. * @return name of the stored procedure
  109. */
  110. public String Procedure
  111. {
  112. get
  113. {
  114. SqlErrorCollection errors = Errors;
  115. return errors.Count > 0 ? errors[0].Procedure : null;
  116. }
  117. }
  118. /**
  119. * Gets the name of the computer running an instance of SQL Server
  120. * that generated the error.
  121. * @return name of the computer where error generated
  122. */
  123. public String Server
  124. {
  125. get
  126. {
  127. SqlErrorCollection errors = Errors;
  128. return errors.Count > 0 ? errors[0].Server : null;
  129. }
  130. }
  131. /**
  132. * Gets a numeric error code from SQL Server that represents an error,
  133. * warning or "no data found" message.
  134. * @return numeric error code from SQL Server
  135. */
  136. public byte State
  137. {
  138. get
  139. {
  140. SqlErrorCollection errors = Errors;
  141. return errors.Count > 0 ? errors[0].State : (byte)0;
  142. }
  143. }
  144. }
  145. }