Board index » delphi » ODBC connection - leaks on simple connect/disconnect - why ?

ODBC connection - leaks on simple connect/disconnect - why ?


2007-01-25 05:48:03 PM
delphi39
Hi,
Im using BCB instead of Delphi, but i think the problem is allround nomatter
what compiler you use.
Very simple, i use the below code and make it run in a continously loop -
and it leaks bigtime.
I made a little ODBC client that fills in some data into a table, and it was
working fine, then i wanted to stresstest it, and then it showed the leak.
I have browsed allover, and i found this KB on MS, then i took my own little
program and replaced it by the one stated below in the article, and the
result is the same, i get the leak:
------------------------------------------------------------------------------------------------------------------------------
Problem described by MS here:
207.46.248.248/kb/232351
Source listing here:
#include <windows.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
#include <assert.h>
#define CK_RT(x) if( x != SQL_SUCCESS && x != SQL_SUCCESS_WITH_INFO)
assert(0)
void main(){
HENV henv;
HDBC hdbc;
RETCODE rc = SQL_SUCCESS;
char *dsnStr="DSN=OracleServer;UID=scott;pwd=tiger;";
short rtnLen = 0;
UCHAR rtnDSN[999] = "";
int i,x;
for (i=0; i < 100; i++)
{
rc = SQLAllocEnv(&henv);
CK_RT(rc);
rc = SQLAllocConnect(henv, &hdbc);
CK_RT(rc);
rc = SQLDriverConnect(hdbc,
NULL,
(unsigned char *)dsnStr,
strlen(dsnStr),
rtnDSN,
255,
&rtnLen,
SQL_DRIVER_NOPROMPT);
CK_RT(rc);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
}
}
--------------------------------------------------------------------------------------------------------------------
The above applies according to the article for Oracle and for NT40, now what
i have here is a very simple setup with a Firebird opensource database, and
the official ODBC driver for this, and ive tested this on XP SP2, and on a
2003 server, with the same annoying results.
Can anybody help me, is the problem im having a real bug (as stated in the
KB) or am i doing something wrong ?
The reason for this stresstest where im opening a connection and kills it
again, is that that would be how the application would work in realtime, so
its pretty important that its possible to create, write, destroy without
leaks.
If im in a wrong newsgroup, then i hope some of you could guide me the right
way - its such a simple program, and its my first ODBC interfacing, then it
hurts alot to hit a memory-leak in first go.
REALLY hope you can help me...thanks.
I dont understand it, it is such a simple piece of code - i will bet it will
happen to any database ?
Is this related to the code, to the databse (firebird) to.....what ? has
anybody gotten anything like this working in Delphi or any other compiler ?
its okay if you talk "delphi'sh" to me :)
 
 

Re:ODBC connection - leaks on simple connect/disconnect - why ?

"Niel Darren" <XXXX@XXXXX.COM>writes
Quote
Hi,
Hi
Quote
Can anybody help me, is the problem im having a real bug (as stated in the
KB) or am i doing something wrong ?
You're not doing anything wrong. The problem described in the KB article
was fixed long ago.
Quote
The reason for this stresstest where im opening a connection and kills it
again, is that that would be how the application would work in realtime,
so
its pretty important that its possible to create, write, destroy without
leaks.
This is a known problem, at least to me.
We have a service that runs 24/7. Every 60 seconds it wakes up, connects to
a DB server, looks for work to do, disconnects and then goes back to sleep
again. In some cases it connects to more than one DB while it is awake. It
has become standard practice for our customers to stop and restart the
service every day or two.
Oracle 9i and DB2 8.1 both leak about 2KB on every pass of your loop. SQL
Server 2000 doesn't leak anything - amazing. Oracle leaks an unnamed
semaphore handle on every connect/disconnect. I don't know what DB2 leaks.
We use MDAC 2.8 SP1. We have never found a solution to the problem. I'm
afraid you will have to find your own workaround.
Also, do yourself a favor and get "Process Explorer" from sysinternals.com.
It's free. Their tools are so good that they were recently aquired by MS.
It's kind of like task manager on stereoids. You can select a process and
then show either the loaded DLLs or handles in its lower window pane.
Showing unnamed handles in the lower pane will show 100 semaphores (Oracle)
just before your test program terminates.
A couple of other points. I built your program in VS2005 (VC++ 8.0), so
it's not BCB THIS time ;-) Using ADO will leak more memory on every loop
pass.
Good luck,
- Arnie