Thread Subject: Mass close db connections?

Subject: Mass close db connections?

From: Mr. A

Date: 2 Jul, 2009 13:27:01

Message: 1 of 2

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.

Subject: Mass close db connections?

From: Sven

Date: 20 Aug, 2009 23:04:04

Message: 2 of 2

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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
database Sven 20 Aug, 2009 19:09:07
connection Sven 20 Aug, 2009 19:09:07
rssFeed for this Thread

Contact us at files@mathworks.com