Is it acceptable to keep a db connection open for the life of the page?

前端 未结 10 1948
执念已碎
执念已碎 2021-01-18 07:11

Everybody knows that you should close a connection immediately after you finish using it.

Due to a flaw in my domain object model design, I\'ve had to leave the conn

10条回答
  •  爱一瞬间的悲伤
    2021-01-18 07:47

    page crashes? this is what using and finally are for

    that said, for the sake of DB performance (i.e. scaling)* it's best to keep connections open as short a period as possible allowing only that you don't want to open close open close open close for rapidly sequential and predictable work

    * I was told this by a mentor early in my career, I must say I've not actually tested this myself but it sounds right theoretically

提交回复
热议问题