<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Last Request Type = CLOSE in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849798#M4880641</link>
    <description>&lt;P&gt;&lt;A href="https://sqlanywhere-forum.sap.com/users/108/jeff-albion/"&gt;@Jeff&lt;/A&gt; I understand that, but who should control DB connection is NHibernate...&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2011 14:01:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-10-24T14:01:13Z</dc:date>
    <item>
      <title>Last Request Type = CLOSE</title>
      <link>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaq-p/13849796</link>
      <description>&lt;P&gt;We launch new version of our internet banking, and at Sybase Central Connected Users panel, I can see a lot of connections with "Last Request Type" equals to "CLOSE".&lt;/P&gt;
&lt;P&gt;Is it normal?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;We use C# 4, with NHibernate and SA11.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Connection pool is enabled with Max Pool Size=100;Min Pool Size=5.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;And I'm getting some of this error: &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;CODE&gt;Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2011 07:05:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaq-p/13849796</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-24T07:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Last Request Type = CLOSE</title>
      <link>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849797#M4880640</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a generic .NET exception that is explained in better detail from &lt;A href="http://blogs.msdn.com/b/spike/archive/2008/08/25/timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from-the-pool.aspx"&gt;other&lt;/A&gt; &lt;A href="http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/c57c0432-c27b-45ab-81ca-b2df76c911ef/"&gt;places&lt;/A&gt;. The basic issue is that you have opened (and closed) a lot of database connections, but the .NET garbage collector has not flagged all of these connections as being available just yet.&lt;/P&gt;
&lt;P&gt;You can possibly try &lt;A href="http://dcx.sybase.com/index.html#1101/en/dbprogramming_en11/connection-pooling-dotnet-dev.html"&gt;increasing the size of the thread pool&lt;/A&gt; or &lt;A href="http://dcx.sybase.com/index.html#1101/en/dbprogramming_en11/ianywhere-data-sqlanywhere-saconnection-connectiontimeout2-0.html"&gt;increase the connection timeout value&lt;/A&gt;, but these are likely temporary measures.&lt;/P&gt;
&lt;P&gt;The most likely issue is that you are not explicitly issuing a &lt;A href="http://dcx.sybase.com/index.html#1101/en/dbprogramming_en11/ianywhere-data-sqlanywhere-saconnection-close2-0.html"&gt;SAConnection.Close()&lt;/A&gt; in your code  and are instead just letting the connection object go out scope. Explicitly issuing the .Close() method (inside of a &lt;A href="http://msdn.microsoft.com/en-us/library/dszsf989%28v=vs.71%29.aspx"&gt;try...catch...finally block&lt;/A&gt; the .Close() should appear in the "finally" clause, or use the SACommand object inside of a &lt;A href="http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx"&gt;using&lt;/A&gt; statement) ensures that the connection is marked for re-use immediately and should free up connections for the rest of your web application users.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;STRONG&gt;Edit:&lt;/STRONG&gt; My apologies - in my original response I neglected the fact that you're using the NHibernate framework.&lt;/P&gt;
&lt;P&gt;NHibernate has the same concept as 'SAConnection' known as '&lt;A href="https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/ISession.cs"&gt;ISession&lt;/A&gt;' and &lt;A href="http://nhforge.org/doc/nh/en/index.html#manipulatingdata-endingsession-close"&gt;you have to manage this object within your NHibernate code&lt;/A&gt; in the same way ("ISession.Close()") to avoid the slower garbage-collection mechanism to free the connections.&lt;/P&gt;
&lt;P&gt;As per the NHibernate documentation, a typical transaction should use the following idiom (Note the 'using' usage):&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;using&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ISession&lt;/SPAN&gt; &lt;SPAN class="n"&gt;session&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;factory&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;OpenSession&lt;/SPAN&gt;&lt;SPAN class="p"&gt;())&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;using&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ITransaction&lt;/SPAN&gt; &lt;SPAN class="n"&gt;tx&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;session&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;BeginTransaction&lt;/SPAN&gt;&lt;SPAN class="p"&gt;())&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;{&lt;/SPAN&gt;
  &lt;SPAN class="n"&gt;try&lt;/SPAN&gt;
  &lt;SPAN class="p"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="sr"&gt;//&lt;/SPAN&gt; &lt;SPAN class="k"&gt;do&lt;/SPAN&gt; &lt;SPAN class="n"&gt;some&lt;/SPAN&gt; &lt;SPAN class="n"&gt;work&lt;/SPAN&gt;
    &lt;SPAN class="o"&gt;...&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;tx&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Commit&lt;/SPAN&gt;&lt;SPAN class="p"&gt;();&lt;/SPAN&gt;
  &lt;SPAN class="p"&gt;}&lt;/SPAN&gt;
  &lt;SPAN class="n"&gt;catch&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Exception&lt;/SPAN&gt; &lt;SPAN class="n"&gt;e&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="p"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="k"&gt;if&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;tx&lt;/SPAN&gt; &lt;SPAN class="o"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;null&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;tx&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Rollback&lt;/SPAN&gt;&lt;SPAN class="p"&gt;();&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;throw&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="p"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;}&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Oct 2011 11:02:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849797#M4880640</guid>
      <dc:creator>jeff_albion</dc:creator>
      <dc:date>2011-10-24T11:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Last Request Type = CLOSE</title>
      <link>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849798#M4880641</link>
      <description>&lt;P&gt;&lt;A href="https://sqlanywhere-forum.sap.com/users/108/jeff-albion/"&gt;@Jeff&lt;/A&gt; I understand that, but who should control DB connection is NHibernate...&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2011 14:01:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849798#M4880641</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-10-24T14:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Last Request Type = CLOSE</title>
      <link>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849799#M4880642</link>
      <description>&lt;P&gt;I've now updated my answer to include information regarding NHibernate.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2011 16:40:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/last-request-type-close/qaa-p/13849799#M4880642</guid>
      <dc:creator>jeff_albion</dc:creator>
      <dc:date>2011-10-24T16:40:25Z</dc:date>
    </item>
  </channel>
</rss>

