I have an asp.net web site and a database.
The web site has a web service for storing feedback from my software.
As far as I know, IIS will reuse the created object for sequential requests.
This gives a reason to connect to the DB in web service's constructor, properly implement Dispose()
method, and use the connection for serving each [WebMethod] Request()
. Current edition follows this patters.
On the other hand I'm afraid that the timespan between sequential requests to webservice will be larger that DB connection timeout. I therefore will need to catch some exception and recreate connection (right?)
The alternative approach is to connect and close in each [WebMethod] Foo()
. But I'm afraid this may hurt the performance.
To sum up,
should I connect to DB in constructor and close connectiion in Dispose()
or connect and close DB for each request?