<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255175</link>
    <title>MATLAB Central Newsreader - Mass close db connections?</title>
    <description>Feed for thread: Mass close db connections?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 02 Jul 2009 13:27:01 -0400</pubDate>
      <title>Mass close db connections?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255175#662201</link>
      <author>Mr. A</author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
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).&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Any help/advice would be appreciated.</description>
    </item>
    <item>
      <pubDate>Thu, 20 Aug 2009 23:04:04 -0400</pubDate>
      <title>Re: Mass close db connections?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255175#674717</link>
      <author>Sven </author>
      <description>Mr. A, did you happen to find a solution to your problem?&lt;br&gt;
I'm afraid I don't have an answer for you, but wanted to add a similar question, which is:&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Method A:&lt;br&gt;
conn = database('mydb','myuser','mypass',...);&lt;br&gt;
mydata = retrieve_db_data(conn);&lt;br&gt;
upload_db_data(mydata, conn);&lt;br&gt;
close(conn)&lt;br&gt;
&lt;br&gt;
Method B:&lt;br&gt;
the &quot;retrieve_db_data()&quot; and &quot;upload_db_data()&quot; functions both create (and close) their own database connections.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Sven&lt;br&gt;
&lt;br&gt;
&quot;Mr. A&quot; &amp;lt;ozan.akcin.nospam@mathworks.com&amp;gt; wrote in message &amp;lt;h2icj5$o9g$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any help/advice would be appreciated.</description>
    </item>
  </channel>
</rss>

