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

前端 未结 5 711
醉酒成梦
醉酒成梦 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 04:55

    In general, .NET's connection pooling should make it 'not matter' as it does a great job of recycling connections for you. But my practice is to use a single connection for a bunch of transactions I know will be taking place together. I think your timings are an indication of the connection pool doing its job and just plain variations in runs.

提交回复
热议问题