gpt4 book ai didi

c# - 连接数据库的正确用法是什么

转载 作者:行者123 更新时间:2023-11-30 14:03:23 24 4
gpt4 key购买 nike

我有一个连接到 SQL Server 2008 的 Winforms 程序。

有 100 个用户连接到这个数据库,并且

运行搜索查询 --> 并更新数据库。

我在程序启动时打开连接,在程序结束时关闭。

这是正确的做法吗?

打开连接 -> 运行查询 -> 更新 -> 并关闭连接是否更好?

提前致谢

最佳答案

is it be better to open connection -> run query -> update -> and close connection ?

是的,SQL Server 已经优化了连接和 pooling is handled by ADO.Net .打开连接使用它来获得你想要的,然后关闭它。让 SQL 管理其余部分。

来自 MSDN(以上来源):

We strongly recommend that you always close the connection when you are finished using it so that the connection will be returned to the pool.

关于c# - 连接数据库的正确用法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4286613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com