Path: news.mathworks.com!not-for-mail
From: "Sven" <sven.holcombe@gmail.deleteme.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Mass close db connections?
Date: Thu, 20 Aug 2009 23:04:04 +0000 (UTC)
Organization: University of Michigan
Lines: 28
Message-ID: <h6kkp4$frg$1@fred.mathworks.com>
References: <h2icj5$o9g$1@fred.mathworks.com>
Reply-To: "Sven" <sven.holcombe@gmail.deleteme.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250809444 16240 172.30.248.38 (20 Aug 2009 23:04:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 23:04:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1326470
Xref: news.mathworks.com comp.soft-sys.matlab:564937


Mr. A, did you happen to find a solution to your problem?
I'm afraid I don't have an answer for you, but wanted to add a similar question, which is:
Is it better to create a single connection to a database, and essentially pass this object around your code? Or, should I create and close connections each time one is needed.

Method A:
conn = database('mydb','myuser','mypass',...);
mydata = retrieve_db_data(conn);
upload_db_data(mydata, conn);
close(conn)

Method B:
the "retrieve_db_data()" and "upload_db_data()" functions both create (and close) their own database connections.

In this very simple example I doubt it makes much difference, but is there a coding practice I should follow to make sure my real-world application doesn't hit trouble? In this, I basically have a loop that retrieves and returns data from/to the database on each iteration, so that the total number of connections made are no longer trivial.

Thanks,
Sven

"Mr. A" <ozan.akcin.nospam@mathworks.com> wrote in message <h2icj5$o9g$1@fred.mathworks.com>...
> Hello,
> 
> I have a bunch of code that uses the Database toolbox and creates connections (generically, 'conn') to various databases. I thought I was quite disciplined in my coding and that I would close every connection (close(conn);) once I was done with it but I'm now finding that there are a bunch of connections left hanging (maxing out connections to the server/db).
> 
> Does anyone know if there is a way of finding any/all hanging connections all in one fell swoop? I was hoping there might be a 'who*' type of function which might return all my hangning connections but I haven't found any such thing.
> 
> In the meantime, I'm going through my code to ensure I have all close(conn) where they should be, but it would be helpful if there were such a utility so that I could just go through and close each connection individually.  My code crawl is likely to take weeks, otherwise.
> 
> Any help/advice would be appreciated.