SqlException.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * @(#)SqlException.java 1.0 01/01/03
  3. *
  4. * Copyright 2002 Mainsoft Corporation. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Mainsoft Corporation.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. namespace System.Data.SqlClient
  11. {
  12. using java.sql;
  13. using System;
  14. using System.Data.ProviderBase;
  15. /**
  16. * The exception that is thrown when SQL Server returns a warning or error.
  17. * This class cannot be inherited.
  18. *
  19. * @author Pavel Sandler
  20. * @version 1.0, 01/01/03
  21. */
  22. /*
  23. * CURRENT LIMITATIONS
  24. * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc)
  25. * is not supported.
  26. * 2. Method "void GetObjectData(...,...)" is not supported (serialization)
  27. */
  28. public sealed class SqlException : AbstractDbException
  29. {
  30. internal SqlException(Exception cause, SqlConnection connection) : base(cause, connection) {}
  31. internal SqlException(SQLException cause, SqlConnection connection) : base(cause, connection) {}
  32. internal SqlException(string message, SQLException cause, SqlConnection connection) : base(message, cause, connection) {}
  33. protected override AbstractDbErrorCollection DbErrors {
  34. get {
  35. return Errors;
  36. }
  37. }
  38. /**
  39. * Gets the severity level of the error returned from the SQL Server .NET
  40. * Data Provider.
  41. * @return severity level of the first error in the collection.
  42. */
  43. public byte Class
  44. {
  45. get
  46. {
  47. SqlErrorCollection errors = Errors;
  48. return errors.Count > 0 ? errors[0].Class : (byte)0;
  49. }
  50. }
  51. /**
  52. * Gets a collection of one or more SqlError objects that give detailed
  53. * information about exceptions generated by the SQL Server .NET Data Provider.
  54. * @return collection of SqlError objects
  55. */
  56. public SqlErrorCollection Errors
  57. {
  58. get
  59. {
  60. return new SqlErrorCollection(_cause, _connection);
  61. }
  62. }
  63. /**
  64. * Gets the line number within the Transact-SQL command batch or stored
  65. * procedure that generated the error.
  66. * @return line number of the first error in the collection.
  67. */
  68. public int LineNumber
  69. {
  70. get
  71. {
  72. SqlErrorCollection errors = Errors;
  73. return errors.Count > 0 ? errors[0].LineNumber : 0;
  74. }
  75. }
  76. /**
  77. * Gets a number that identifies the type of error.
  78. * @return number that identifies the type of first error in the collection
  79. */
  80. public int Number
  81. {
  82. get
  83. {
  84. SqlErrorCollection errors = Errors;
  85. return errors.Count > 0 ? errors[0].Number : 0;
  86. }
  87. }
  88. /**
  89. * Gets the name of the stored procedure or remote procedure call (RPC)
  90. * that generated the error.
  91. * @return name of the stored procedure
  92. */
  93. public String Procedure
  94. {
  95. get
  96. {
  97. SqlErrorCollection errors = Errors;
  98. return errors.Count > 0 ? errors[0].Procedure : null;
  99. }
  100. }
  101. /**
  102. * Gets the name of the computer running an instance of SQL Server
  103. * that generated the error.
  104. * @return name of the computer where error generated
  105. */
  106. public String Server
  107. {
  108. get
  109. {
  110. SqlErrorCollection errors = Errors;
  111. return errors.Count > 0 ? errors[0].Server : null;
  112. }
  113. }
  114. /**
  115. * Gets a numeric error code from SQL Server that represents an error,
  116. * warning or "no data found" message.
  117. * @return numeric error code from SQL Server
  118. */
  119. public byte State
  120. {
  121. get
  122. {
  123. SqlErrorCollection errors = Errors;
  124. return errors.Count > 0 ? errors[0].State : (byte)0;
  125. }
  126. }
  127. }
  128. }