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

前端 未结 5 719
醉酒成梦
醉酒成梦 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:10

    Definitively, it's better to have one connection. Maybe you are running your benchmark with small amount of data. Try increasing the number to 1,000 or 10,000.

    Another point is that, depending on your app configuration, you might think you are running with multiple connections but .NET is pooling connections for you, so you are basically running with the same connections.

提交回复
热议问题