0

I have a Webservice written in VB.net which has several endpoints and i register the Routes in my WebApiConfig.vb. As there is no Startup page i am not sure where i can make the call on startup to initialize my db connection.

NoSoup4you
  • 640
  • 1
  • 10
  • 34
  • I think, you don't want to initialize your db connection unless you do something with it. Sounds like you planning to keep live connection for duration of your app. Are you planning to reuse it between calls to your controllers? – T.S. Mar 12 '20 at 19:41
  • Yes, i want to keep the connection open as the db has something called cluster manager which manages the connection and if it drops reopens it etc. – NoSoup4you Mar 12 '20 at 19:52
  • 1
    You're going into wrong direction. you should open connection for every db call / transaction. you should not use same connection. If two of your end points are hit simultaneously, how are you going to share the connection? – T.S. Mar 12 '20 at 21:09
  • 1
    As T.S suggested, I think you might be heading in the wrong direction. each endpoint in your service should be effectively thought of as a standalone program that manages it's own state and resources. Sharing a single connection is not a good idea – Hursey Mar 12 '20 at 21:35
  • The db sdk has something called cluster manager which handles the connections etc. So in my case i want to create the cluster instance and then keep using it. If it drops the cluster manager will handle the reconnect etc. – NoSoup4you Mar 12 '20 at 21:52
  • I don't think you understand what is cluster manager. See this to what you NEED to do [How to keep single SQL Server connection instance open for multiple request in C#?](https://stackoverflow.com/questions/48210258/how-to-keep-single-sql-server-connection-instance-open-for-multiple-request-in-c) – T.S. Mar 12 '20 at 22:18

0 Answers0