currently i create a ASP.NET WebApi application. Due to RESTful Applications are Session-Stateless i am thinking about how to preserve a open database connection? I also could reopen the database everytime a user sends a WebApi request.
But which solution would be the better one?
- Try to preserve the database connection – but how?
- Re-Open the connection everytime a user sends a WebApi request?
Thanks, Andreas
You should keep the connection open as little as possible. Close the connection right after you finished using it. Connection Pooling in .NET will handle physical connections to DB for you so you don’t have to worry about performance. You will actually impact performance by keeping open connections for a long period of time.