Sometimes OCI invalid handle error

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hegyesi
Posts: 4
Joined: Mon 07 Jan 2013 15:56

Sometimes OCI invalid handle error

Post by hegyesi » Wed 04 Dec 2019 16:45

Hello Support team,

We have got a web application which throws OCI invalid handle exceptions sometimes.

Message: OCI invalid handle.
Source: Devart.Data.Oracle
StackTrace: at Devart.Data.Oracle.bx.d(Int32 A_0)
at Devart.Data.Oracle.dw.b(Int32 A_0)
at Devart.Data.Oracle.OracleDataReader.Read()

Code:

Code: Select all

                        
                        OracleCommand mo_Command = new OracleCommand();
                        mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
                        mo_Command.CommandType = System.Data.CommandType.Text;
                        mo_Command.Connection = mo_Connection;
                        decimal mn_Sid = -1;
                        using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
                        {
                            using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                            {
                                mo_Reader.Read();   //throws OCI invalid handle sometimes
                                mn_Sid = mo_Reader.GetDecimal(0);
                                mo_Reader.Close();
                            }
                        }
                        mo_ConnectionDescriptor.ConnectionSID = mn_Sid;
We use dotConnect for Oracle 9.9.867.0.

Do you have any idea what should I try to get rid of this exception?

Thanks in advance for your help.

Istvan

Shalex
Site Admin
Posts: 9023
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Fri 06 Dec 2019 13:23

Please give us additional information:

1) the version (xx.x) and capacity (x64 or x86) of your Oracle Client

2) the version (xx.x.x.x.x) and edition of your Oracle Server

3) your connection string (mark confidential information with asterisks)

4) run your code snippet in a for loop and specify the approximate number of iterations will be passed before throwing "OCI invalid handle"?

Code: Select all

    for (int i = 0; i < length; i++)
    {
        using (var mo_Connection = new OracleConnection(connectionString))
        {
            OracleCommand mo_Command = new OracleCommand();
            mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
            mo_Command.CommandType = System.Data.CommandType.Text;
            mo_Command.Connection = mo_Connection;
            decimal mn_Sid = -1;
            using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
            {
                using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                {
                    mo_Reader.Read();   //throws OCI invalid handle sometimes
                    mn_Sid = mo_Reader.GetDecimal(0);
                    mo_Reader.Close();
                }
            }
        }
    }
    

hegyesi
Posts: 4
Joined: Mon 07 Jan 2013 15:56

Re: Sometimes OCI invalid handle error

Post by hegyesi » Tue 10 Dec 2019 16:34

Hi Shalex,

Thank you for your help.
Oracle client 32 bit and 11.2.0
Oracle server: 11g Release 11.2.0.3.0

I created a for loop for testing. Two times it threw exception after 74 cycle.

Exception:
Errors in file :
OCI-21500: internal error code, arguments: [KGHFRE3], [0x5982710], [], [], [], [], [], []


----- Call Stack Trace -----
calling call entry argument values in hex
location type point (? means dubious value)
-------------------- -------- -------------------- ----------------------------
_skgudmp()+100 CALLrel _kgdsdst() 489E68D 489ED14 53FC
_kgerin()+133 CALLreg 00000000 53FC 59FDF48
_kghnerror()+275 CALLrel _kgerin() 59FDF48 5A320C0 6EC97E7C 1 2
5982710
_kghfre()+4877 CALLrel _kghnerror() 59FDF48 5A05428 6EC97E7C
5982710 4 D0000035
_kpuhhfre()+1037 CALLrel _kghfre() 489EE00 0 6FDE3682 59FDF48
5A05428
_kpuxcStmCtxTerm()+ CALLrel _kpuhhfre() 59FD960 5982724 702B2E60
27
_kpufhndl0..0()+109 CALLrel _kpuxcStmCtxTerm() 5983108 832660 0 5983108
48 59FD960 1
_kpufhndl()+13 CALLrel _kpufhndl0..0() 2 A1C9EC 6FEFF8A2
_OCIHandleFree()+34 CALLptr 00000000 5983108 4
0564B2D9 CALLreg 00000000 5983108 4
05B65F7D CALLrel 05B654C0 2727D30 5983108 489FBD4
5B65E4D 2727D30 5983108
05B65E4A CALLreg 00000000 2727D30 5983108 489FBD4
2727D30 0 0
05B65944 CALLreg 00000000 1 0 0 489FBF0 2727AEC 2727E1C
05B671F8 CALLreg 00000000 DB1065 2727E1C 0 489FC38
A1C9EC 489FC84
60E7A2D1 CALLreg 00000000 489FC74 60F46C80 489FE38
60E7A27B CC210AC5 100
60E7A3D2 CALLrel 60E7A254 0 A1C9EC 2727E1C 0 0 2727E1C
60E7A10D CALLrel 60E7A338 2727E1C 7B9BA0 2727E1C
60E7A19B CC210B49 0
60E7A20A CALLrel 60E7A116 0 489FD27 489FE38 60E79C10 1
FFFFFF
60E79CB5 CALLrel 60E79D12 CC210B25 489FE38 60E79C10 0
3601C4 7BB110
60F4D95C CALLreg 00000000 489FE7C 7CFB20 489FE7C
489FE1C 60F4D9E9 CC21085D
60F4D9E4 CALLrel 60F4D920 CC21085D 60F41930 489FE7C 0 0
0
60F4D8D4 CALLrel 60F4D963 CC210831 60F41930 60E79C10 0
C8CAEAB0 60D9FE5C
60F41917 CALLrel 60F4D863 1 0 7B9BA0 0 60E79C10 489FE7C
60F419F8 CALLrel 60F418D1 CC210895 60F41930 0 7B33F0
CC210885 0
60F4A8B5 CALLreg 00000000 0 0 0 0 0 0
74F60417 CALLreg 00000000 7B33F0 74F60400 489FFD8
7781662D 7B33F0 85341342
7781662B CALLreg 00000000 7B33F0 85341342 0 0 7B33F0 0
778165F8 CALLrel 778165FE FFFFFFFF 778351D3 0 0
60F4A860 7B33F0
00000000 CALL??? 00000000

Call stack signature: 0x6e5b92cba08a3c05



call stack performance statistics:
total : 0.281000 sec
setup : 0.188000 sec
stack unwind : 0.000000 sec
symbol translation : 0.062000 sec
printing the call stack: 0.031000 sec
printing frame data : 0.000000 sec
printing argument data : 0.000000 sec


----- End of Call Stack Trace -----

75. kör: 103

Nem kezelt kivétel: System.AccessViolationException: Védett memória olvasására vagy írására történt kísérlet. Ez gyakran arra utal, hogy a memória más területe sérült.
a következő helyen: OciDynamicType.nativeOCIHandleFree(HandleRef , Int32 )
a következő helyen: OciDynamicType.OCIHandleFree(HandleRef , Int32 )
a következő helyen: Devart.Data.Oracle.dw.k()
a következő helyen: Devart.Data.Oracle.OracleDataReader.Close()
a következő helyen: Devart.Data.Oracle.OracleDataReader.Finalize()


Testing code:

Code: Select all

        
        static void Main(string[] args)
        {
            OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder();
            builder.Server = "fejleszt11n";
            builder.UserId = "pir2019_meo";
            builder.Password = "xxx";
            builder.Pooling = false;
            for (int i = 0; i < 300; i++)
            {
                OracleCommand mo_Command = new OracleCommand();
                mo_Command.CommandText = "select sys_context('USERENV','SID') as sid from dual";
                mo_Command.CommandType = System.Data.CommandType.Text;
                using (OracleConnection mo_Connection = new OracleConnection(builder.ConnectionString))
                {
                    mo_Connection.Open();
                    mo_Command.Connection = mo_Connection;
                    decimal mn_Sid = -1;
                    using (OracleCursor mo_Cursor = mo_Command.ExecuteCursor())
                    {
                        using (OracleDataReader mo_Reader = mo_Cursor.GetDataReader())
                        {
                            mo_Reader.Read();
                            mn_Sid = mo_Reader.GetDecimal(0);
                            mo_Reader.Close();
                        }
                    }
                    mo_Connection.Close();
                    mo_Connection.Dispose();
                    Console.WriteLine($"{i+1}. kör: {mn_Sid}");
                }
            }
        }
        
I checked the same code with direct connection. I tried it lot of times without any exception.

Thank you for your help in advance.

Istvan

Shalex
Site Admin
Posts: 9023
Joined: Thu 14 Aug 2008 12:44

Re: Sometimes OCI invalid handle error

Post by Shalex » Thu 19 Dec 2019 15:16

We cannot reproduce the issue with Oracle Client 11.2.0.1.

1. Are you using instant client or full version of Oracle Client?

2. Check the properties of your \11.2.0\client_1\bin\oraclient11.dll and tell us its exact version (11.2.0.x).

Post Reply