OciServerHandle.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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, IOciHandle, IDisposable
  21. {
  22. #region Fields
  23. bool attached;
  24. OciErrorHandle errorHandle;
  25. string tnsname;
  26. #endregion // Fields
  27. #region Constructors
  28. public OciServerHandle (OciEnvironmentHandle environment, IntPtr handle)
  29. : base (OciHandleType.Server, environment, handle)
  30. {
  31. attached = false;
  32. }
  33. #endregion // Constructors
  34. #region Properties
  35. public OciErrorHandle ErrorHandle {
  36. get { return errorHandle; }
  37. set { errorHandle = value; }
  38. }
  39. public string TNSName {
  40. get { return tnsname; }
  41. set { tnsname = value; }
  42. }
  43. #endregion // Properties
  44. #region Methods
  45. [DllImport ("oci")]
  46. public static extern int OCIServerAttach (IntPtr srvhp,
  47. IntPtr errhp,
  48. string dblink,
  49. [MarshalAs (UnmanagedType.U4)] int dblink_len,
  50. uint mode);
  51. [DllImport ("oci")]
  52. public static extern int OCIServerDetach (IntPtr srvhp,
  53. IntPtr errhp,
  54. uint mode);
  55. public bool Attach ()
  56. {
  57. int status = 0;
  58. status = OCIServerAttach (Handle,
  59. errorHandle.Handle,
  60. tnsname,
  61. tnsname.Length,
  62. 0);
  63. attached = (status == 0);
  64. return attached;
  65. }
  66. public void Dispose ()
  67. {
  68. if (attached) {
  69. OCIServerDetach (Handle,
  70. errorHandle.Handle,
  71. 0);
  72. }
  73. Environment.FreeHandle (this);
  74. }
  75. #endregion // Methods
  76. }
  77. }