OciServerHandle.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // OciServerHandle.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 OciServerHandle : OciHandle, IDisposable
  21. {
  22. #region Fields
  23. bool disposed = false;
  24. bool attached = false;
  25. OciErrorHandle errorHandle;
  26. #endregion // Fields
  27. #region Constructors
  28. public OciServerHandle (OciHandle parent, IntPtr newHandle)
  29. : base (OciHandleType.Server, parent, newHandle)
  30. {
  31. }
  32. #endregion // Constructors
  33. #region Methods
  34. public bool Attach (string tnsname, OciErrorHandle error)
  35. {
  36. errorHandle = error;
  37. int status = OciCalls.OCIServerAttach (this, error, tnsname, tnsname.Length, 0);
  38. if (status != 0) {
  39. OciErrorInfo info = errorHandle.HandleError ();
  40. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  41. }
  42. attached = true;
  43. return attached;
  44. }
  45. public void Detach (OciErrorHandle error)
  46. {
  47. if (!attached)
  48. return;
  49. int status = OciCalls.OCIServerDetach (this, error, 0);
  50. if (status != 0) {
  51. OciErrorInfo info = errorHandle.HandleError ();
  52. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  53. }
  54. attached = false;
  55. }
  56. protected override void Dispose (bool disposing)
  57. {
  58. if (!disposed) {
  59. try {
  60. Detach (errorHandle);
  61. disposed = true;
  62. } finally {
  63. base.Dispose (disposing);
  64. }
  65. }
  66. }
  67. #endregion // Methods
  68. }
  69. }