I am currently building a WCF Web Service which may have 5 endpoints or even more. Each of these endpoints’ methods will need to access a SQL Server database (for different reasons, though), and, of course, these endpoints may be called by several clients at the same time. In this scenario, what is the best way to manage connections to the database?
1) Have each method open and close a SQLConnection every time it is accessed?
2) Have a static ConnectionManager object with a SQLConnection property permanently open?
3) None of the above. Which, then?
Thank you very much!
The correct approach is 1) + connection pooling which is used by default if all your connections connect to database under single account (pool is per unique connection string which contains user login). Connection pooling ensures that connections are reused for multiple operations but it is absolutely transparent to development process.