Ronny,

I think this is actually quite simple.  All of your statistic/information
says you are not closing the connection... so where in your code are you
closing the connection?

In one of my projects, I open the data manager as:

// open a MySql database
if (!(sock=mysql_init(0)))
{
_lclose(hfile);
MessageBox(hDlg,"Couldn't initialize mysql struct","Convert SportsLog
Data",MB_OK);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}

// mysql_options(sock,MYSQL_READ_DEFAULT_GROUP,"connect");
if
(!mysql_real_connect(sock,ipNumber,userName,password,gvDatabase,3306,NULL,0)
)
{
_lclose(hfile);
sprintf(tstuff,"Couldn't connect to engine!\n%s\n",mysql_error(sock));
MessageBox(hDlg,tstuff,"Convert SportsLog Data",MB_OK);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}

if (mysql_select_db(sock,gvDatabase))
{
_lclose(hfile);
sprintf(tstuff,"Couldn't select database test: Error: %s\n",
mysql_error(sock));
MessageBox(hDlg,tstuff,"Convert SportsLog Data",MB_OK);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}

Then, I use the following code to select, etc.:

if (mysql_real_query(sock, query, strlen(query))) {
queryError(query);
}

After I pull the information I want out of the result set, I close the
result set with:

mysql_free_result(tableRes);

At the end of the program, I close the socket.

Note two things:

1.  I don't open a connection for each query, using the already open socket
instead (good for some things, not good for other ones.)  But, for the
appropriate applications, it is very fast.

2.  You have to free the result set after every select.

By the way, this code came right out of Googling.

Thanks and good luck,

Carl


----- Original Message -----
From: "Ronny Melz" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Sunday, June 05, 2005 4:57 PM
Subject: Re: sleeping processes


>
> Thanks so far for your advice,
>
> > Is it possible that your application doesn't close connection properly?
> that is exactly what also I think is the problem's cause, but I am unable
to
> locate the place where it actually does happen. My code seems
straightforward
> and I had looked over it some other more experienced people which were
unable
> to find the bug as well... weird
>
> > Check with netstat the states of connections between your application
> > and server.
> '$ netstat | grep mysql' dumps a list increasing proportionally to 'mysql>
> show full processlist' up to the point where max_connections are reached:
> then the mysql processlist reports max_connections+1 pids (including the
> terminal I use to get the processlist) whereas a '$ netstat | grep mysql |
wc
> -l' does never return due to an ever increasing number of open
connections.
> Each of them is in state TIME_WAIT.
>
> > Do you see some sleeping processes
> > with ps utility or 'mysqladmin processlist' command?
> AFAIK, 'mysqladmin processlist' prints the same as a 'mysql> show full
> processlist', right? It's max_connections sleeping processes plus the
> processlist query.
>
> Your hint to watch out for sleeping processes with ps was interesting.
> Actually, I have some 14 processes ('ps lax | grep mysql') without running
my
> program but max_connections+14 if it is running. Each of the processes is
> sleeping. I still don't have any idea, do you?
>
> Any suggestions appreciated.
> Ronny
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.323 / Virus Database: 267.6.2 - Release Date: 6/4/2005
>
>



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.6.2 - Release Date: 6/4/2005


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to