I've an asp.internet site along with a database.

The site includes a web service for storing feedback from the software.

So far as I understand, IIS will reuse the produced object for consecutive demands. This provides grounds for connecting towards the DB in web service's constructor, correctly implement Dispose() method, and employ the bond for serving each [WebMethod] Request(). Current edition follows this patters.

However I am afraid the timespan between consecutive demands to webservice is going to be bigger that DB connection timeout. I therefore will have to catch some exception and recreate connection (right?)

The choice approach would be to connect and near the coast each [WebMethod] Foo(). But I am afraid this might hurt the performance.

To summarize, must i connect with DB in constructor and close connectiion in Dispose() or connect and close DB for every request?

You need to connect for every request.

The page instance is just employed for just one request, which means you can't store an association inside it to reuse it. You would need to store it elsewhere, which is really complicated (with thread safety and the like) it's certainly not worthwhile.

Whenever you close the bond, the particular database connection is came back towards the connection pool. The bond pool takes proper care of resetting the bond correctly when it is used again for the following connection object that you simply create, to ensure that you receive a connection that's alive and pristine by previous usage.

The bond pool works fine, and you ought to utilize it rather than attempting to create one yourself.

It's not necessary to do anything whatsoever special to make use of the bond pooling, it's included in the database driver. Just open and shut connection objects as always.

ADO.Internet 2. let's start, DB Connections are put, so actual frequent lowering and raising of connections are handled by DB Connection pool, you are able to freely open and shut them inside your individual techniques since the Pool could keep them open until a timeout. You may also configure the pool configurations.

Have you got any connection pooling facilities available? Your WS objects would grab an association in the pool, and send them back their when finished. The pool handles timeouts and real frequent lowering and raising.

My order of approach could be:

1). for those who have connectio pooling utilize it.

2). Otherwise make it simple, open and shut on each request. Writing a thread-safe connection pool isn't trivial.

3). If performance turns out to be an issue then investigate when the connect-each-time overhead may be the cause. If that's the case, look for a pool implmentaiotn or (last measure) code pooling oneself.