查询有关SQL数据适配器 [英] Query about SQL Data Adapter

查看:133
本文介绍了查询有关SQL数据适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否需要打开和关闭用于使用数据适配器获取数据的sql连接.

预先感谢.

Is it necessary to open and close a sql connection for fetching data using data adapter.

Thanks in advance.

推荐答案

否.
http://msdn.microsoft.com/en-us/library/system. data.sqlclient.sqldataadapter.aspx [ ^ ]

请注意,该代码不会显式打开和关闭连接.如果Fill方法发现连接尚未打开,则隐式打开DataAdapter正在使用的Connection.如果填充"打开了连接,则在填充"完成时,它也会关闭连接.当处理诸如填充或更新之类的单个操作时,这可以简化您的代码.但是,如果要执行多个需要打开连接的操作,则可以通过显式调用Connection的Open方法,对数据源执行操作,然后调用Connection的Close方法来提高应用程序的性能.您应该努力在最短的时间内保持与数据源的连接打开,以释放其他客户端应用程序要使用的资源.
参考: http://msdn.microsoft.com/en-us/library /bh8kx08z(v=vs.71).aspx [ ^ ]
No.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx[^]

Note that the code does not explicitly open and close the Connection. The Fill method implicitly opens the Connection that the DataAdapter is using if it finds that the connection is not already open. If Fill opened the connection, it will also close the connection when Fill is finished. This can simplify your code when dealing with a single operation such as a Fill or an Update. However, if you are performing multiple operations that require an open connection, you can improve the performance of your application by explicitly calling the Open method of the Connection, performing the operations against the data source, then calling the Close method of the Connection. You should strive to keep connections to the data source open for a minimal amount of time to free up the resource to be used by other client applications.
Ref:http://msdn.microsoft.com/en-us/library/bh8kx08z(v=vs.71).aspx[^]


这篇关于查询有关SQL数据适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆