SqlError.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // System.Data.SqlClient.SqlError
  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 System.Data.ProviderBase;
  33. using java.sql;
  34. using System.Data.Common;
  35. /**
  36. * Collects information relevant to a warning or error returned by SQL Server.
  37. */
  38. [Serializable]
  39. public class SqlError : AbstractDbError
  40. {
  41. string _serverVersion;
  42. /**
  43. * Initialize SqlError object
  44. * */
  45. internal SqlError(SQLException e, AbstractDBConnection connection) : base(e, connection)
  46. {
  47. if (connection != null)
  48. _serverVersion = connection.ServerVersion;
  49. }
  50. /**
  51. * Overridden. Gets the complete text of the error message.
  52. *
  53. * @return A string representation of the current object.
  54. */
  55. public override String ToString()
  56. {
  57. return String.Concat("SqlError:", Message, _e.StackTrace);
  58. }
  59. /**
  60. * Gets the name of the provider that generated the error.
  61. *
  62. * @return The name of the provider
  63. */
  64. public String Source
  65. {
  66. get
  67. {
  68. return DbSource;
  69. }
  70. }
  71. /**
  72. * Gets a number that identifies the type of error.
  73. *
  74. * @return Number of the error
  75. */
  76. public int Number
  77. {
  78. get
  79. {
  80. return DbErrorCode;
  81. }
  82. }
  83. /**
  84. * Gets a numeric error code from SQL Server that represents an error,
  85. * warning or "no data found" message. For more information on how to
  86. * decode these values, see SQL Server Books Online.
  87. *
  88. * @return Error Code
  89. */
  90. public byte State
  91. {
  92. get
  93. {
  94. return 0; // & BitConstants.ALL_BYTE;
  95. }
  96. }
  97. /**
  98. * Gets the severity level of the error returned from SQL Server.
  99. *
  100. * @return Severity level of the error
  101. */
  102. public byte Class
  103. {
  104. get
  105. {
  106. return 0; // & BitConstants.ALL_BYTE;
  107. }
  108. }
  109. /**
  110. * Gets the name of the instance of SQL Server that generated the error.
  111. *
  112. * @return The name of the server
  113. */
  114. public String Server
  115. {
  116. get
  117. {
  118. return _serverVersion;
  119. }
  120. }
  121. /**
  122. * Gets the text describing the error.
  123. *
  124. * @return The text describing the error
  125. */
  126. public String Message
  127. {
  128. get
  129. {
  130. return DbMessage;
  131. }
  132. }
  133. /**
  134. * Gets the name of the stored procedure or remote procedure call (RPC)
  135. * that generated the error.
  136. *
  137. * @return The name of stored procedure that generated the error.
  138. */
  139. public String Procedure
  140. {
  141. get
  142. {
  143. return null;
  144. }
  145. }
  146. /**
  147. * Bets the line number within the Transact-SQL command batch or stored
  148. * procedure that contains the error.
  149. *
  150. * @return Line number of error in stored procedure
  151. */
  152. public int LineNumber
  153. {
  154. get
  155. {
  156. return 0;
  157. }
  158. }
  159. }
  160. }