When should I open and close a connection to SQL Server

前端 未结 6 1032
慢半拍i
慢半拍i 2020-12-12 19:09

I have a simple static class with a few methods in it. Each of those methods open a SqlConnection, query the database and close the connection. This way, I am sure that I al

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 20:15

    Most programmers believe in open late and close early. This is only a problem if the latency for opening and closing the connection each time causes the entire application to slow down.

    In your case with a static class it is probably best to open and close the connection each time.

提交回复
热议问题