Home » Developer & Programmer » Precompilers, OCI & OCCI » Oracle Connection not getting closed (Oracle 9i,11g - Windows 2003 server)
Oracle Connection not getting closed [message #452983] Mon, 26 April 2010 12:02 Go to next message
prax_14
Messages: 64
Registered: July 2008
Member
Hi all,

I have Multi-threaded application using pro*c to connect to oracle.

I am using the following piece of code to create a connection to oracle database and preserver the context of created connection.
    struct sqlca * tempSqlca = new sqlca;
    struct sqlca & sqlca = * tempSqlca;

    EXEC SQL BEGIN DECLARE SECTION;

        SQL_CONTEXT localContext;
        const char * user = param.getUser().c_str();
        const char  * password = param.getPassword().c_str();
        const char  * dbConnection = param.getDbConnection().c_str();

    EXEC SQL END DECLARE SECTION;

    EXEC SQL CONTEXT ALLOCATE :localContext;
    EXEC SQL WHENEVER SQLERROR GOTO sql_error_tag;
    EXEC SQL CONTEXT USE :localContext;

    if (strlen(dbConnection) == 0) 
	{
        EXEC SQL CONNECT :user IDENTIFIED BY :password;
    }
    else 
	{
        EXEC SQL CONNECT :user IDENTIFIED BY :password USING :dbConnection;
    }

    // Copy the new context to returned context 
    connection.context  = DivaSqlContext(localContext);
    connection.ca       = &sqlca;
    return true;

    sql_error_tag:

    // Free all memory associated with the runtime context
    // and place a null pointer in the host program variable 
    EXEC SQL CONTEXT FREE :localContext;
    connection.context  = 0;
    // Delete the allocated sqlca
    delete &sqlca;
    tempSqlca = 0;
    connection.ca = 0;


I am using the following piece of code to close the connection to the oracle database, I am using the context created in the previous step and passing it to the below code(connection.context)to release the connection.

    if (connection.context == 0 || connection.ca == 0)
        return true;

    // Multithreading: get the communication area of the context
    struct sqlca & sqlca = *(connection.ca);
	
    EXEC SQL BEGIN DECLARE SECTION;
        SQL_CONTEXT localContext = SQL_CONTEXT(connection.context);
    EXEC SQL END DECLARE SECTION;

    // Use this context for following part: freeing context
    EXEC SQL CONTEXT USE :localContext;

    // Free all memory associated with a runtime context
    // and place a null pointer in the host program variable
	EXEC SQL CONTEXT FREE :localContext;

    // Delete the allocated sqlca
    delete &sqlca;
    connection.ca = 0;
    // Copy the deleted context to given context.
    connection.context = DivaSqlContext(localContext);
    return true;


When the above code is executed there is no exception thrown but the connection is not getting close. I am using the V$SESSION system views to monitor the connection created.

Can anyone see why ? I there anything I am missing in my code for the connection closing to fail.
Re: Oracle Connection not getting closed [message #453167 is a reply to message #452983] Tue, 27 April 2010 09:44 Go to previous message
prax_14
Messages: 64
Registered: July 2008
Member
Hi all,

Can anyone please help me on this issue.

Thank you,
Prakash R
Previous Topic: Pro*C Compiler errors on C Code.
Next Topic: Precompiler for Fortran
Goto Forum:
  


Current Time: Mon Sep 27 02:49:07 CDT 2021