什么是最佳实践(每次一个全局连接或创建新连接) [英] What is best practice (One Global connection or Create new connection every time)
问题描述
我在WPF中使用VB脚本开发了一个Windows基础应用程序,数据库是SQL Server 2012和水晶报告我在启动我的应用程序时打开了一个sql连接并使用这个连接字符串这样Dim sqlconn作为SqlConnection = Application.Current。整个应用程序中的属性(sqlcn)。此连接仅在应用程序关闭时关闭。
我应该怎么做?
当我创建每个表单的新实例时新的连接
或
我的正确逻辑是最好的
I have developed a windows base application in WPF with VB Script, database is SQL Server 2012 and crystal report I have open a sql connection while starting my application and using this connection string this way Dim sqlconn As SqlConnection = Application.Current.Properties("sqlcn") in entire application in. This connection close only when application will close.
What should I do?
when I create new instance of every form with new connection
or
My correct logic is best
推荐答案
你应该只在你打开连接时想要访问数据库,并在收到结果后立即将其关闭。
You should open a connection only when you want to access the database, and close it as soon as you receive the results.
这篇关于什么是最佳实践(每次一个全局连接或创建新连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!