SqlError.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //------------------------------------------------------------------------------
  2. // <copyright file="SqlError.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. namespace System.Data.SqlClient {
  9. using System;
  10. using System.Diagnostics;
  11. using System.Globalization;
  12. [Serializable]
  13. public sealed class SqlError {
  14. // bug fix - MDAC 48965 - missing source of exception
  15. // fixed by [....]
  16. private string source = TdsEnums.SQL_PROVIDER_NAME;
  17. private int number;
  18. private byte state;
  19. private byte errorClass;
  20. [System.Runtime.Serialization.OptionalFieldAttribute(VersionAdded=2)]
  21. private string server;
  22. private string message;
  23. private string procedure;
  24. private int lineNumber;
  25. [System.Runtime.Serialization.OptionalFieldAttribute(VersionAdded=4)]
  26. private int win32ErrorCode;
  27. internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber, uint win32ErrorCode)
  28. : this(infoNumber, errorState, errorClass, server, errorMessage, procedure, lineNumber)
  29. {
  30. this.win32ErrorCode = (int)win32ErrorCode;
  31. }
  32. internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber) {
  33. this.number = infoNumber;
  34. this.state = errorState;
  35. this.errorClass = errorClass;
  36. this.server = server;
  37. this.message = errorMessage;
  38. this.procedure = procedure;
  39. this.lineNumber = lineNumber;
  40. if (errorClass != 0) {
  41. Bid.Trace("<sc.SqlError.SqlError|ERR> infoNumber=%d, errorState=%d, errorClass=%d, errorMessage='%ls', procedure='%ls', lineNumber=%d\n" ,
  42. infoNumber, (int)errorState, (int)errorClass, errorMessage,
  43. procedure == null ? "None" : procedure, (int)lineNumber);
  44. }
  45. this.win32ErrorCode = 0;
  46. }
  47. // bug fix - MDAC #49280 - SqlError does not implement ToString();
  48. // I did not include an exception stack because the correct exception stack is only available
  49. // on SqlException, and to obtain that the SqlError would have to have backpointers all the
  50. // way back to SqlException. If the user needs a call stack, they can obtain it on SqlException.
  51. public override string ToString() {
  52. //return this.GetType().ToString() + ": " + this.message;
  53. return typeof(SqlError).ToString() + ": " + this.message; // since this is sealed so we can change GetType to typeof
  54. }
  55. // bug fix - MDAC #48965 - missing source of exception
  56. // fixed by [....]
  57. public string Source {
  58. get { return this.source;}
  59. }
  60. public int Number {
  61. get { return this.number;}
  62. }
  63. public byte State {
  64. get { return this.state;}
  65. }
  66. public byte Class {
  67. get { return this.errorClass;}
  68. }
  69. public string Server {
  70. get { return this.server;}
  71. }
  72. public string Message {
  73. get { return this.message;}
  74. }
  75. public string Procedure {
  76. get { return this.procedure;}
  77. }
  78. public int LineNumber {
  79. get { return this.lineNumber;}
  80. }
  81. internal int Win32ErrorCode {
  82. get { return this.win32ErrorCode; }
  83. }
  84. }
  85. }