How to keep single SQL Server connection instance open for multiple request in C#?

后端 未结 2 766
渐次进展
渐次进展 2020-12-22 13:27

I have a Web API which contains database insert logic (ado.net) in C#. When multiple users (e.g. 100 users) call the Web API, every time a SQL Server connection is opened an

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 14:15

    Well it's easy you just have to keep the connection open and if any readers opened they are closed.

    var con = new SqlConnection("Your connection String");
       con.open();
       //your code
    con.close()//after you have done your executions
    

    Have you tried Linq. It does the same thing you want, it keeps the connection alive and i think it'll be easier for you

提交回复
热议问题