OciErrorHandle.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // OciErrorHandle.cs
  3. //
  4. // Part of managed C#/.NET library System.Data.OracleClient.dll
  5. //
  6. // Part of the Mono class libraries at
  7. // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
  8. //
  9. // Assembly: System.Data.OracleClient.dll
  10. // Namespace: System.Data.OracleClient.Oci
  11. //
  12. // Author:
  13. // Tim Coleman <[email protected]>
  14. //
  15. // Copyright (C) Tim Coleman, 2003
  16. //
  17. using System;
  18. using System.Runtime.InteropServices;
  19. namespace System.Data.OracleClient.Oci {
  20. internal sealed class OciErrorHandle : OciHandle, IOciHandle, IDisposable
  21. {
  22. #region Constructors
  23. public OciErrorHandle (OciEnvironmentHandle environment, IntPtr handle)
  24. : base (OciHandleType.Error, environment, handle)
  25. {
  26. }
  27. #endregion // Constructors
  28. #region Methods
  29. public void Dispose ()
  30. {
  31. Environment.FreeHandle (this);
  32. }
  33. public OciErrorInfo HandleError ()
  34. {
  35. OciErrorInfo info;
  36. info.ErrorCode = 0;
  37. info.ErrorMessage = String.Empty;
  38. int errbufSize = 512;
  39. IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
  40. OciGlue.OCIErrorGet (Handle,
  41. 1,
  42. IntPtr.Zero,
  43. out info.ErrorCode,
  44. errbuf,
  45. (uint) errbufSize,
  46. OciHandleType.Error);
  47. object err = Marshal.PtrToStringAnsi (errbuf);
  48. if (err != null) {
  49. string errmsg = (string) err;
  50. info.ErrorMessage = String.Copy (errmsg);
  51. Marshal.FreeHGlobal (errbuf);
  52. }
  53. return info;
  54. }
  55. #endregion // Methods
  56. }
  57. }