A tool that tracks the number of sql connects and disconnects.

forum.cdk (1998-2005) & forum.td.cdk (2005-2010)

A tool that tracks the number of sql connects and disconnects.

Post by Prakash » 19 May 2006, 10:29

 Posted by:  Prakash 

Hi All,
Very often we face this situation that the number of cursors
exceeds the maximum number of connections possible to a database and get No
Sql Cursors Remaining error and the application crashes.I am aware of the
fact that it comes bcos of un-disconnected sql handles and if the number
exceeds 99 from ctd. What i am looking at is a tracer tool which we can
write in cdk which when switched on logs the information of connections with
formwindow , function name if its from a function or a table window or any
other parent or child windows.
Can anyone tell me if this is possble using cdk?

If so where should i start ?

Is there any existing samples which could help me out with this.

Thanks in advance


Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2366
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: A tool that tracks the number of sql connects and disconnects.

Post by Jeff Luther » 19 May 2006, 18:57

 Posted by:  Jeff Luther 

You could write a CDK utility to parse an appl. and look for mis-matching,
though it might only get close, since a disconnect might well be in another
function, say, than where the connect is. But that would be a separate appl.
itself and not some underlying CDK code that ran below your appl.

Years ago I helped rewrite a SQLBase-only appl. to be able to support connects
to Oracle and SQL Server, and the basic way we attacked that problem was to
have all SQL calls go through a series of functions we wrote that parsed
the incoming generic sql, changed the sql depending on the backend and passed
it on so it was compatible with that db.

** Save your appl. to a new name before making changes below! **, then...

If it were me with your issue, I would consider writing a function that replaced
your connect/disconnect calls and wrote to a log/trace file of what and where
a call was made, and kept track of non-balanced connects/disconnects. Write the
function so that a replace of "SqlConnect(" and "SqlDisconnect(" could be done
with extra parms. and a minimum of effort. Maybe a function like:
Function: SqlConnectMgr
Boolean: bConnect ! T = connect, F = disconnect
String: sCalledFrom ! like "myFunct" or "SAM_Create" value-could be a # parm.
Sql Handle: hSql

Now, based on a global (unless it's another parm.) bool. and global file handle
you can write out whether connect or disconnect, and where the call was made,
etc. Then, based on bConnect...
If bConnect
Return SqlConnect( hSql )
Return SqlDisconnect( hSql )

To change your appl. you would Replace:
"SqlConnect(" --> "SqlConnectMgr( TRUE, \'\',"
and that should replace "SqlConnect( hSql )"
with "SqlConnectMgr( TRUE, '', hSql )"

For disconnect, Replace:
"SqlDisonnect(" --> "SqlConnectMgr( FALSE, \'\', "

You would then need to find instances of "" and by hand edit
those to add in tokens like "SAM_AppStartup", "SAM_AppExit", "frmMain-SAM_Create"
and so on. If you have hundreds of these to edit, you could use the CDK
to parse your changed appl. and depending on the code level at the moment,
change "" to the current msg, function name, etc.

A CDK utility could be written to do this entire process for you--and if you
have may appls. it might be worth it to--but unless you know the CDK the
learning curve can be quite high and with a a single appl. to change the
manual method I described above would likely be easier.

If you don't know the CDK I have a small code sample on my web page link below.

Best Regards,
Jeff Luther/PC Design
info: www.pulpcards.com/gupta/


Re: A tool that tracks the number of sql connects and disconnects.

Post by Futch » 14 Jun 2006, 16:28

 Posted by:  futch 

A. Design your app to work from a pool of connected handles. If you've got
more than 2-3 cursors open at any one time (in general) then you need to
redesign your app - sorry to sound facecious.

B. Write wrapper functions for SqlConnect/SqlDisconnect to manage your
connections. The wrapper can write whatever you want to a log file - the sql
handle, the form window name ( SalGetItemName( hWndForm, sFormName) )

C. Write wrapper functions for all of your SqlPrepare/Execute. Again, the
wrapper writes to a log (if you've enabled it).

If you want to query the # connections on the server, I have a couple of
Sybase/MSSql queries to count connections from an app.

Return to “td.cdk”

Who is online

Users browsing this forum: [Ccbot] and 0 guests