OleDbException.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // System.Data.OleDb.OleDbException
  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.OleDb
  31. {
  32. using java.sql;
  33. using System.Text;
  34. using System.Data.Common;
  35. using System.Data.ProviderBase;
  36. /*
  37. * CURRENT LIMITATIONS
  38. * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc)
  39. * is not supported.
  40. * 2. Method "void GetObjectData(...,...)" is not supported (serialization)
  41. */
  42. #if NET_2_0
  43. public sealed class OleDbException : AbstractDbException
  44. {
  45. internal OleDbException (Exception cause, OleDbConnection connection) : base (cause, connection) { }
  46. internal OleDbException (SQLException cause, OleDbConnection connection) : base (cause, connection) { }
  47. internal OleDbException (string message, SQLException cause, OleDbConnection connection) : base (message, cause, connection) { }
  48. protected override AbstractDbErrorCollection DbErrors {
  49. get {
  50. return Errors;
  51. }
  52. }
  53. public OleDbErrorCollection Errors {
  54. get {
  55. return new OleDbErrorCollection (_cause, _connection);
  56. }
  57. }
  58. public override int ErrorCode {
  59. get {
  60. return DbErrorCode;
  61. }
  62. }
  63. }
  64. #else
  65. public sealed class OleDbException : System.Runtime.InteropServices.ExternalException
  66. {
  67. private class OleDbExceptionImpl : AbstractDbException {
  68. internal OleDbExceptionImpl(Exception cause, OleDbConnection connection) : base(cause, connection) {}
  69. internal OleDbExceptionImpl(SQLException cause, OleDbConnection connection) : base(cause, connection) {}
  70. internal OleDbExceptionImpl(string message, SQLException cause, OleDbConnection connection) : base(message, cause, connection) {}
  71. protected override AbstractDbErrorCollection DbErrors {
  72. get {
  73. return Errors;
  74. }
  75. }
  76. public OleDbErrorCollection Errors {
  77. get {
  78. return new OleDbErrorCollection(_cause, _connection);
  79. }
  80. }
  81. public int ErrorCode {
  82. get {
  83. return DbErrorCode;
  84. }
  85. }
  86. }
  87. OleDbExceptionImpl _impl;
  88. internal OleDbException(Exception cause, OleDbConnection connection) : base(null, cause) {
  89. _impl = new OleDbExceptionImpl(cause, connection);
  90. }
  91. internal OleDbException(SQLException cause, OleDbConnection connection) : base(null, cause) {
  92. _impl = new OleDbExceptionImpl(cause, connection);
  93. }
  94. internal OleDbException(string message, SQLException cause, OleDbConnection connection) : base(null, cause) {
  95. _impl = new OleDbExceptionImpl(message, cause, connection);
  96. }
  97. /**
  98. * Gets a collection of one or more SqlError objects that give detailed
  99. * information about exceptions generated by the SQL Server .NET Data Provider.
  100. * @return collection of SqlError objects
  101. */
  102. public OleDbErrorCollection Errors
  103. {
  104. get
  105. {
  106. return (OleDbErrorCollection)_impl.Errors;
  107. }
  108. }
  109. /**
  110. * Gets the error code of the error.
  111. * @return The error code of the error.
  112. */
  113. public override int ErrorCode
  114. {
  115. get
  116. {
  117. return base.HResult;
  118. }
  119. }
  120. /**
  121. * Gets the name of the OLE DB provider that generated the error.
  122. * @return the name of the OLE DB provider that generated the error.
  123. */
  124. public override String Source
  125. {
  126. get
  127. {
  128. return _impl.Source;
  129. }
  130. }
  131. public override string Message {
  132. get {
  133. return _impl.Message;
  134. }
  135. }
  136. }
  137. #endif
  138. }