Database User Connections

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 02-Nov-2005 19:43:00   

I'm starting to think I'm doing something wrong in the way I'm coding the adapter class to connect to the database. I have been watching the database using Performance Monitor and keep seeing that the db User Connections will exceed 50+ when using the web site I'm developing. I had thought that the connection pool would keep this down to only a few connections. What can I do to fix this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Nov-2005 21:41:09   

Normally the connection is closed immediately after the action is done. Do you keep an adapter around? Do you call Dispose a lot?

It can be there are more than 50 simultaneous users doing actions.

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 02-Nov-2005 22:01:47   

Should I always call Dispose after using the adapter? Below is a typical way for calling the adapter to fetch either an entity or a collection. This is all being done using a web application and I am the only person using it.

public FrameColorEntity GetFrameColor(int frameColorID)
{
    FrameColorEntity color = new FrameColorEntity(frameColorID);
    DataAccessAdapter adapter = new DataAccessAdapter();
    adapter.FetchEntity(color);
    return color;
}
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Nov-2005 23:32:51   

depends on the db. On sqlserver, it's ok, on oracle, or firebird, you're better off calling dispose as well (so apply a using statement).

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 03-Nov-2005 00:57:08   

Does the using statement call the CloseConnection() and Dispose() methods?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 03-Nov-2005 03:01:47   

The using statement will call dispose when done. Take a look here for a little more information. I believe the dispose method for the DataAccessAdapter will close the connection. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_8_13.asp

Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 03-Nov-2005 03:10:36   

Otis, you might want to add this to the Best Practices section of the docs as i too was wondering this same thing. Of course i found it eventually by searching teh forum, but it should reallly be stated in the docs IMHO.

I apologize if its in there, but i read the entire doc manual last week and i dont recall seeing it in there simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Nov-2005 09:47:24   

Good point. simple_smile

Frans Bouma | Lead developer LLBLGen Pro