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".

Is it normal?

We use C# 4, with NHibernate and SA11.

Connection pool is enabled with Max Pool Size=100;Min Pool Size=5.

And I'm getting some of this error:

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.

asked 24 Oct '11, 07:05

Zote's gravatar image

Zote
1.7k364051
accept rate: 43%

edited 15 Mar '13, 21:00

Mark%20Culp's gravatar image

Mark Culp
24.9k10139297


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.

This is a generic .NET exception that is explained in better detail from other places. 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.

You can possibly try increasing the size of the thread pool or increase the connection timeout value, but these are likely temporary measures.

The most likely issue is that you are not explicitly issuing a SAConnection.Close() in your code and are instead just letting the connection object go out scope. Explicitly issuing the .Close() method (inside of a try...catch...finally block the .Close() should appear in the "finally" clause, or use the SACommand object inside of a using statement) ensures that the connection is marked for re-use immediately and should free up connections for the rest of your web application users.


Edit: My apologies - in my original response I neglected the fact that you're using the NHibernate framework.

NHibernate has the same concept as 'SAConnection' known as 'ISession' and you have to manage this object within your NHibernate code in the same way ("ISession.Close()") to avoid the slower garbage-collection mechanism to free the connections.

As per the NHibernate documentation, a typical transaction should use the following idiom (Note the 'using' usage):

using (ISession session = factory.OpenSession())
using (ITransaction tx = session.BeginTransaction())
{
  try
  {
    // do some work
    ...
    tx.Commit();
  }
  catch (Exception e)
  {
    if (tx != null) tx.Rollback();
    throw;
  }
}
permanent link

answered 24 Oct '11, 11:02

Jeff%20Albion's gravatar image

Jeff Albion
10.8k171175
accept rate: 25%

edited 24 Oct '11, 16:39

@Jeff I understand that, but who should control DB connection is NHibernate...

(24 Oct '11, 14:01) Zote
Comment Text Removed

I've now updated my answer to include information regarding NHibernate.

(24 Oct '11, 16:40) Jeff Albion
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×76
×23
×15
×9
×8

question asked: 24 Oct '11, 07:05

question was seen: 3,553 times

last updated: 15 Mar '13, 21:00