Is it better to execute many sql commands with one connection, or reconnect every time?

前端 未结 5 712
醉酒成梦
醉酒成梦 2020-12-01 04:11

Here\'s my test code, which seems to suggest that it\'s better to connect multiple times instead of connecting just once.

Am I doing something wrong?



        
5条回答
  •  鱼传尺愫
    2020-12-01 05:03

    SqlClient will pool your connections. In your first case with one open, it will do the job of opening the connection. Every other run will use the pooled connection. If you reverse your order and do "many connections" first, I would expect you to see the opposite result.

提交回复
热议问题