cancel
Showing results for 
Search instead for 
Did you mean: 

How to close timeout connection in SQLDBC ?

Former Member
0 Kudos

Hello,

I use SQLDBC to access MAXDB 7.7.0.7.16 database, i have the following issue :

When a connection reach timeout, I close the connection, and the release the connexion, and then I create a new connection

To close connection I call my Disconnect function

The call close method return "Not connected", but It seems that the underlying Socket is not closed and the Database user task is not closed.

So the number of task grow until it reach the maximun.

Where is my error ?

How can I be sure to close the database user task ?

IDBError CMaxDBConnection::Disconnect()

{

IDBError hr;

if (m_pConnection)

{

EDPTRACE_DBG_INF(L"CMaxDBConnection::Disconnect %1", EDPMASK_TRC_CONNECTIONS) << (DWORD)m_pConnection;

SQLDBC_Retcode rc = m_pConnection->close();

if (SQLDBC_OK != rc)

{

hr = convertError(rc, m_pConnection->error(), L"CMaxDBConnection::Disconnect");

}

m_pParent->m_pEnvironment->releaseConnection(m_pConnection);

m_pConnection = NULL;

}

return hr;

}

Regards

Yann

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello,

I add RECONNECT properties but it does not change any thing.

Here is the new code :

SQLDBC::SQLDBC_ConnectProperties properties;

properties.setProperty("RECONNECT", "0");

rc = conn->connect(connectArgs.host, connectArgs.dbname,

connectArgs.username, connectArgs.password, properties);

Do you have any idea how to avoid leak ?

Can I manually close task as a workaround ?

Yann.

Former Member
0 Kudos

Thanks for your answer.

After investigation, it is not only a reconnect issue, as explain in my previous reply.

In fact the SESSIONS, table has the right number of sessions but a task stay alive.

I do not understand why one of the two user task is not close when the connection is closed. Even if the connection is not in timeout.

As workaround, can we manually close all users task in "Command Wait" state and without "APPLICATION SERVER" ?

I can try RECONNECT=0, but where do I set RECONNECT = 0

I set RECONNECT as a SQLDBC::SQLDBC_ConnectProperties ?

thanks for help

Yann.

alexander_schroeder
Participant
0 Kudos

Yes, as a connect property.

Former Member
0 Kudos

MAXDB 7.7.07.16 (WINDOWS 2008 R2 (64 bits) Client program in 32bits.

Hello

I have code a small program to illustrate my issue.

When I create a connection with SQLDBC it create 2 user tasks in the MAXDB task Manager

One uer task APPPLICATION SERVER, SESSION TIMOUT, ... filled.

T425 10 0x16AC User 2688* Command wait 823 0 76 20691065(s)

and One User task with no session tiemout.

T111 8 0x15B8 User 2688 Command wait 3009 0 76 24900501(s)

-


T111 USER ( pid = 2688 ) -


dispatcher_cnt: 2 command_cnt : 2

exclusive_cnt : 30 self_susp_cnt : 0

state_vwait : 0 state_vsleep : 0 state_vsusp : 0

same_ukt_coll : 0

-


when I close the connection the task T111 is never remove !!

Do you have any idea ?

I try to delete environment but It does not work.

Regards

Yann.

Here is the code :

// SQLDBC.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "SQLDBC.h"

using namespace SQLDBC;

static void parseArgs(int argc, wchar_t **argv);

static SQLDBC_Connection *connectDB();

SQLDBC_Environment *g_env;

typedef struct ConnectArgsT {

bstrt username;

bstrt password;

bstrt dbname;

bstrt host;

bstrt request;

} ConnectArgsT;

ConnectArgsT connectArgs;

void exitOnError(SQLDBC_ErrorHndl &err);

int _tmain(int argc, _TCHAR* argv[])

{

SQLDBC_Retcode ret;

parseArgs(argc, argv);

for (int j = 0 ; j < 10 ; ++j)

{

for (int i = 0 ; i < 100 ; ++ i)

{

SQLDBC_Connection *conn = connectDB();

ret = conn->close();

ret = conn->disconnect();

g_env->releaseConnection(conn);

}

delete g_env;

g_env = NULL;

}

return 0;

}

SQLDBC_Connection *connectDB()

{

char errorText[200];

SQLDBC_Retcode rc;

if (g_env == NULL)

{

/*

  • Every application has to initialize the SQLDBC library by getting a

  • reference to the ClientRuntime and calling the SQLDBC_Environment constructor.

*/

SQLDBC_IRuntime *runtime;

runtime = SQLDBC::GetClientRuntime(errorText, sizeof(errorText));

if (!runtime) {

fprintf(stderr, "Getting instance of the ClientRuntime failed %s\n", errorText);

}

g_env = new SQLDBC_Environment(runtime);

}

/*

  • Create a new connection object and open a session to the database.

*/

SQLDBC_Connection *conn = g_env->createConnection();

printf("Connecting to '%s' on '%s' as user '%s'\n",

(char)connectArgs.dbname, (char)connectArgs.host, (char*)connectArgs.username);

rc = conn->connect(connectArgs.host, connectArgs.dbname,

connectArgs.username, connectArgs.password);

if(SQLDBC_OK != rc) {

fprintf(stderr, "Can't connect to '%s'.\nERROR: %d:'%s'\n",

connectArgs.dbname, conn->error().getErrorCode(), conn->error().getErrorText());

exit(1);

conn->setAutoCommit(SQLDBC_TRUE);

}

return conn;

}

static void parseArgs (int argc, wchar_t **argv)

{

connectArgs.username = "ESKDBADM";

connectArgs.password = "DELORME";

connectArgs.dbname = "EDP350";

connectArgs.host = "ly-delorme";

}

void exitOnError(SQLDBC_ErrorHndl &err)

{

if(err) {

fprintf(stderr, "Execution stopped %d:'%s'", err.getErrorCode(), err.getErrorText());

//exit(1);

}

}

Yann.

alexander_schroeder
Participant
0 Kudos

Hi Yann,

when a connection is closed with a time-out, it is always the server closing the session because of the timeout,

never the client.

So when that timeout happens, and you assume there is a dangling connection, can you

do a SELECT * FROM SESSIONS and look whether its 'still there' - the application pid should match your client program.

Maybe you did something between timeout and got a reconnect, so trying with connect option RECONNECT=0 to be

extra sure no reconnect is happening.

Kind Regards

Alexander