2005-12-20 Daniel Morgan <danielmorgan@verizon.net>
authorDaniel Morgan <monodanmorg@yahoo.com>
Wed, 21 Dec 2005 03:44:38 +0000 (03:44 -0000)
committerDaniel Morgan <monodanmorg@yahoo.com>
Wed, 21 Dec 2005 03:44:38 +0000 (03:44 -0000)
* System.Data.OracleClient/OracleConnectionPoolManager.cs
* System.Data.OracleClient/OracleConnectionPool.cs
* System.Data.OracleClient/OracleConnection.cs
* System.Data.OracleClient/OciGlue.cs
* System.Data.OracleClient.Oci/OciEnvironmentHandle.cs
* System.Data.OracleClient.Oci/OciErrorHandle.cs
* System.Data.OracleClient.Oci/OciServiceHandle.cs
* System.Data.OracleClient.Oci/OciSessionHandle.cs: modified
- support Integrated Security which is external authentication
- dispose of OCI handles properly to prevent SEGSIGV during finalization
at application exit

svn path=/trunk/mcs/; revision=54672

mcs/class/System.Data.OracleClient/ChangeLog
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciEnvironmentHandle.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciErrorHandle.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciServiceHandle.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciSessionHandle.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OciGlue.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleConnection.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleConnectionPool.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleConnectionPoolManager.cs

index c14d6257e150ff165162454469898810e3333e5f..c2db5f130b0766ac2db73d15c517f7f0b4b279ff 100644 (file)
@@ -1,3 +1,17 @@
+2005-12-20  Daniel Morgan <danielmorgan@verizon.net>
+
+       * System.Data.OracleClient/OracleConnectionPoolManager.cs
+       * System.Data.OracleClient/OracleConnectionPool.cs
+       * System.Data.OracleClient/OracleConnection.cs
+       * System.Data.OracleClient/OciGlue.cs
+       * System.Data.OracleClient.Oci/OciEnvironmentHandle.cs
+       * System.Data.OracleClient.Oci/OciErrorHandle.cs
+       * System.Data.OracleClient.Oci/OciServiceHandle.cs
+       * System.Data.OracleClient.Oci/OciSessionHandle.cs: modified
+               - support Integrated Security which is external authentication
+               - dispose of OCI handles properly to prevent SEGSIGV during finalization
+               at application exit
+
 2005-12-19  Daniel Morgan <danielmorgan@verizon.net>
 
        * System.Data.OracleClient/OracleConnectionPoolManager.cs
index 663fe51f6e15d3d0cdf7b6058c87ad975c8574fe..67367ae8c8699dadaf1c57522f9bae4886f540a5 100644 (file)
@@ -50,28 +50,7 @@ namespace System.Data.OracleClient.Oci {
 
                public OciErrorInfo HandleError ()
                {
-                       int errbufSize = 512;
-                       IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
-
-                       OciErrorInfo info;
-                       info.ErrorCode = 0;
-                       info.ErrorMessage = String.Empty;
-
-                       OciCalls.OCIErrorGet (Handle,
-                                       1,
-                                       IntPtr.Zero,
-                                       out info.ErrorCode,
-                                       errbuf,
-                                       (uint) errbufSize,
-                                       OciHandleType.Environment);
-
-                       object err = Marshal.PtrToStringAnsi (errbuf);
-                       if (err != null) {
-                               string errmsg = (string) err;
-                               info.ErrorMessage = String.Copy (errmsg);
-                               Marshal.FreeHGlobal (errbuf);
-                       }
-
+                       OciErrorInfo info = OciErrorHandle.HandleError (this);
                        return info;
                }
 
index 3e402bed5e597eadb4d7cd1dc014f2448ecb2f52..c299eddaef5a5092c4f76aa0d5e7d25d58d51a0b 100644 (file)
@@ -47,7 +47,7 @@ namespace System.Data.OracleClient.Oci {
                        }
                }
 
-               public OciErrorInfo HandleError (
+               public static OciErrorInfo HandleError (OciHandle hand
                {
                        OciErrorInfo info;
                        info.ErrorCode = 0;
@@ -56,7 +56,7 @@ namespace System.Data.OracleClient.Oci {
                        int errbufSize = 4096;
                        IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
 
-                       OciCalls.OCIErrorGet (this
+                       OciCalls.OCIErrorGet (hand
                                1,
                                IntPtr.Zero,
                                out info.ErrorCode,
@@ -64,24 +64,36 @@ namespace System.Data.OracleClient.Oci {
                                (uint) errbufSize,
                                OciHandleType.Error);
 
-                       //object err = Marshal.PtrToStringAuto (errbuf);\r
                        byte[] bytea = new byte[errbufSize];\r
                        Marshal.Copy (errbuf, bytea, 0, errbufSize);\r
                        errbufSize = 0;\r
+                       \r
+                       OciHandle h = hand.Parent;\r
+                       if (h == null)\r
+                               h = hand;\r
+\r
                        // first call to OCICharSetToUnicode gets the size\r
-                       OciCalls.OCICharSetToUnicode (Parent, null, bytea, out errbufSize);\r
+                       OciCalls.OCICharSetToUnicode (h, null, bytea, out errbufSize);\r
                        StringBuilder str = new StringBuilder (errbufSize);\r
+                       \r
                        // second call to OCICharSetToUnicode gets the string\r
-                       OciCalls.OCICharSetToUnicode (Parent, str, bytea, out errbufSize);\r
+                       OciCalls.OCICharSetToUnicode (h, str, bytea, out errbufSize);\r
+                       \r
                        string errmsg = String.Empty;\r
                        if (errbufSize > 0)\r
                                errmsg = str.ToString ();\r
+                       \r
                        info.ErrorMessage = String.Copy (errmsg);\r
                        Marshal.FreeHGlobal (errbuf);
 
                        return info;
                }
 
+               public OciErrorInfo HandleError () 
+               {
+                       return HandleError (this);
+               }
+
                #endregion // Methods
        }
 }
index 41e0c8763868ed577487ba44220061d86f6b2d65..d1c6a7a56f2f70add8ccd88c8687310d1a903d65 100644 (file)
@@ -56,10 +56,10 @@ namespace System.Data.OracleClient.Oci {
                        if (!disposed) {
                                try {
                                        if (disposing) {
-                                               if (server != null)
-                                                       server.Dispose ();
-                                               if (session != null)
-                                                       session.Dispose ();
+                                               //if (server != null)
+                                               //      server.Dispose ();
+                                               //if (session != null)
+                                               //      session.Dispose ();
                                        }
                                        disposed = true;
                                } finally {
index 45947ecaa81cfb78ff369a7c9b676a78504c2427..c7b48e1bb50861005c6cd8cdd53ccb5d34a358f8 100644 (file)
@@ -29,6 +29,7 @@ namespace System.Data.OracleClient.Oci {
                bool disposed = false;
                string username;
                string password;
+               OciCredentialType credentialType;
 
                #endregion // Fields
 
@@ -48,13 +49,13 @@ namespace System.Data.OracleClient.Oci {
                        set { serviceHandle = value; }
                }
 
-               public string Username {
+               internal string Username {
                        get { return username; }
                        set { username = value; }
                }
 
-               public string Password {
-                       get { return password; }
+               internal string Password {
+                       get { return String.Empty; }
                        set { password = value; }
                }
 
@@ -68,25 +69,27 @@ namespace System.Data.OracleClient.Oci {
 
                        int status = 0;
 
-                       status = OciCalls.OCIAttrSetString (this,
-                                                       OciHandleType.Session,
-                                                       username,
-                                                       (uint) username.Length,
-                                                       OciAttributeType.Username,
-                                                       errorHandle);
-
-                       if (status != 0) 
-                               return false;
-
-                       status = OciCalls.OCIAttrSetString (this,
-                                                       OciHandleType.Session,
-                                                       password,
-                                                       (uint) password.Length,
-                                                       OciAttributeType.Password,
-                                                       errorHandle);
-
-                       if (status != 0) 
-                               return false;
+                       if (credentialType == OciCredentialType.RDBMS) {
+                               status = OciCalls.OCIAttrSetString (this,
+                                       OciHandleType.Session,
+                                       username,
+                                       (uint) username.Length,
+                                       OciAttributeType.Username,
+                                       errorHandle);
+
+                               if (status != 0) 
+                                       return false;
+
+                               status = OciCalls.OCIAttrSetString (this,
+                                       OciHandleType.Session,
+                                       password,
+                                       (uint) password.Length,
+                                       OciAttributeType.Password,
+                                       errorHandle);
+
+                               if (status != 0) 
+                                       return false;
+                       }
 
                        status = OciCalls.OCISessionBegin (Service,
                                                errorHandle,
@@ -107,13 +110,14 @@ namespace System.Data.OracleClient.Oci {
                        if (!begun)
                                return;
                        OciCalls.OCISessionEnd (Service, error, this, 0);
+                       begun = false;
                }
 
                protected override void Dispose (bool disposing)
                {
                        if (!disposed) {
                                try {
-                                       EndSession (errorHandle);
+                                       //EndSession (errorHandle);
                                        disposed = false;
                                } finally {
                                        base.Dispose (disposing);
index a04b88a61159a0ef3a7bf90bed39661198daac55..c278123549aa1a014ba9552eb4c993348f3e91a8 100644 (file)
@@ -132,7 +132,7 @@ namespace System.Data.OracleClient.Oci {
                                throw new OracleException (info.ErrorCode, info.ErrorMessage);
                        }
 
-                       if (!session.BeginSession (OciCredentialType.RDBMS, OciSessionMode.Default, ErrorHandle)) {
+                       if (!session.BeginSession (conInfo.CredentialType, OciSessionMode.Default, ErrorHandle)) {
                                OciErrorInfo info = error.HandleError ();
                                Disconnect ();
                                throw new OracleException (info.ErrorCode, info.ErrorMessage);
@@ -175,16 +175,28 @@ namespace System.Data.OracleClient.Oci {
 
                public void Disconnect() 
                {
-                       if (session != null)
+                       if (session != null) {
+                               session.EndSession (error);
                                session.Dispose ();
-                       if (server != null)
+                               session = null;
+                       }
+                       if (server != null) {
+                               server.Detach (error);
                                server.Dispose ();
-                       if (error != null)
+                               server = null;
+                       }
+                       if (error != null) {
                                error.Dispose ();
-                       if (service != null)
+                               error = null;
+                       }
+                       if (service != null) {
                                service.Dispose ();
-                       if (environment != null)
+                               service = null;
+                       }
+                       if (environment != null) {
                                environment.Dispose ();
+                               environment = null;
+                       }
                }
 
                #endregion // Methods
index e825bd5d8d1fc7c60328e1d52f507b079202bf2b..b96e0d385f57e3c8d4f220a48040fba0ede2e01c 100644 (file)
@@ -32,6 +32,7 @@ using System.Data;
 using System.Data.OracleClient.Oci;
 using System.Drawing.Design;
 using System.EnterpriseServices;
+using System.Globalization;
 using System.Text;
 
 namespace System.Data.OracleClient 
@@ -42,6 +43,7 @@ namespace System.Data.OracleClient
                internal string Password;
                internal string Database;
                internal string ConnectionString;
+               internal OciCredentialType CredentialType;
        }
 
        [DefaultEvent ("InfoMessage")]
@@ -351,6 +353,7 @@ namespace System.Data.OracleClient
                        conInfo.Username = "";
                        conInfo.Database = "";
                        conInfo.Password = "";
+                       conInfo.CredentialType = OciCredentialType.RDBMS;
 
                        if (connectionString == String.Empty)
                                return;
@@ -420,7 +423,11 @@ namespace System.Data.OracleClient
                                        // TODO:
                                        break;
                                case "INTEGRATED SECURITY":
-                                       throw new NotImplementedException ();
+                                       if (ConvertToBoolean("integrated security", value) == false)
+                                               conInfo.CredentialType = OciCredentialType.RDBMS;
+                                       else
+                                               conInfo.CredentialType = OciCredentialType.External;
+                                       break;
                                case "PERSIST SECURITY INFO":
                                        // TODO:
                                        break;
@@ -443,18 +450,7 @@ namespace System.Data.OracleClient
                                        conInfo.Username = value;
                                        break;
                                case "POOLING" :
-                                       switch (value.ToUpper ()) {
-                                       case "YES":
-                                       case "TRUE":
-                                               pooling = true;
-                                               break;
-                                       case "NO":
-                                       case "FALSE":
-                                               pooling = false;
-                                               break;
-                                       default:
-                                               throw new ArgumentException("Connection parameter not supported: '" + name + "'");
-                                       }
+                                       pooling = ConvertToBoolean("pooling", value);
                                        break;
                                default:
                                        throw new ArgumentException("Connection parameter not supported: '" + name + "'");
@@ -462,6 +458,22 @@ namespace System.Data.OracleClient
                        }
                }
 
+               private bool ConvertToBoolean(string key, string value) 
+               {
+                       string upperValue = value.ToUpper();
+
+                       if (upperValue == "TRUE" ||upperValue == "YES") {
+                               return true;
+                       } 
+                       else if (upperValue == "FALSE" || upperValue == "NO") {
+                               return false;
+                       }
+
+                       throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
+                               "Invalid value \"{0}\" for key '{1}'.", value, key));
+               }
+
+
                ~OracleConnection() 
                {
                        Dispose (false);
index 1602fd500ca4d3a610faf037269f4e88e26d384b..195275afd8e338bcb97660c3331925e1a7ab6b63 100644 (file)
@@ -97,21 +97,16 @@ namespace System.Data.OracleClient
                        return manager.CreateConnection (info);
                }
 
-               ~OracleConnectionPool ()
+               public void Dispose () 
                {
                        if (list != null) {
-                               if (list.Count > 0) {
-                                       for (int c = 0; c < list.Count; c++) {
-                                               // There are available connections in the pool
-                                               OciGlue connection = (OciGlue)list [c];
-                                               list.RemoveAt (c);
-                                               if (connection.Connected) {
+                               if (list.Count > 0)
+                                       foreach (OciGlue connection in list)
+                                               if (connection.Connected)
                                                        connection.Disconnect ();
-                                                       connection = null;
-                                               }
-                                       }
-                               }
-                       }
+                               list.Clear ();
+                               list = null;
+                       }                       
                }
        }
 }
index 22013ec4ac369cd6f9c493507647c4e440ebda38..804052d82a83371458a33c8cfc8db655b4695a7e 100644 (file)
@@ -58,8 +58,19 @@ namespace System.Data.OracleClient
                        return oci;
                }
 
+               public void Dispose () 
+               {
+                       if (pools != null) {
+                               foreach (OracleConnectionPool pool in pools)
+                                       pool.Dispose ();
+                               pools.Clear ();
+                               pools = null;
+                       }
+               }
+
                ~OracleConnectionPoolManager () 
                {
+                       Dispose ();
                }
        }
 }