C# ADO.NET中断开连接和连接方法的确切含义是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15564485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is exactly meaning of disconnected and connected approach in ADO.NET
提问by Suri
I am learning ADO.Net. I read this line:-
我正在学习 ADO.Net。我读了这一行:-
DataReader is "connected" approach and dataset is "disconnected" approach
DataReader 是“连接”的方法,数据集是“断开的”方法
From this sentence I have reached to this conclusion that in data reader we need to establish the connection to the database while in dataset we do not need to establish the connection to the data base.
从这句话我得出这个结论,在数据阅读器中我们需要建立到数据库的连接,而在数据集中我们不需要建立到数据库的连接。
But how without establishing the connection one can access data.I know I am not getting the exact meaning.
但是如何不建立连接就可以访问数据。我知道我没有得到确切的含义。
Please any one can tell me the exact meaning with example.
请任何人都可以通过示例告诉我确切的含义。
回答by TalentTuner
Disconnected = Make Connection , Fetch Data , Close Connection
断开连接 = 建立连接,获取数据,关闭连接
Connected = Make Connection , Keep Connection alive , Close Connection when close is called.
Connected = Make Connection , Keep Connection alive , Close Connection 当调用 close 时。
For more information , please see the link on MSDN
有关更多信息,请参阅MSDN上的链接
回答by Adeel
Think DataSet as in memory database, it contains DataTables and contain tables data (all or subset of data based on Select query) and even maintain relations among tables. On the DataSet you can perform update/delete operations, it will be synched to database through DataAdapter object. so to display data it does not need to be connected to database All time as DataReader, which needs to be connected to database whenever you want to display data.
将 DataSet 视为内存数据库,它包含 DataTables 和包含表数据(基于 Select 查询的所有或数据子集),甚至维护表之间的关系。在DataSet 上可以执行更新/删除操作,它会通过DataAdapter 对象同步到数据库。所以要显示数据,它不需要一直连接到数据库作为DataReader,只要你想显示数据就需要连接到数据库。
回答by NoviceProgrammer
In classic ADO the RecordSet
object could work both in connected and disconnected mode. In Ado.Net there are two separate types available to cater to each of these scenarios - IDataReader
and DataSet
在经典的 ADO 中,RecordSet
对象可以在连接和断开连接模式下工作。在 Ado.Net 中有两种不同的类型可用于满足这些场景中的每一种 -IDataReader
和DataSet
Connected Mode: remains connected to the underlying data source while traversing in a forward-only streams of result sets.
连接模式:在只前向的结果集流中遍历时保持与底层数据源的连接。
Disconnected Mode: the resultset retrieved is kept in memory and the connection to the DB is no longer needed for traversal.
断开连接模式:检索到的结果集保存在内存中,不再需要与数据库的连接进行遍历。
This MSDN articlefurther compares the two objects and discusses their individual merits a lot better than I will be able to explain here.
这篇MSDN 文章进一步比较了这两个对象并讨论了它们各自的优点,比我在这里解释的要好得多。
回答by Deepak Raj
The ADO.net architecture, in which connection must be kept open till the end to retrieve and access data from database is called as connected architecture. Connected architecture is built on the these types - connection
, command
, datareader
ADO.net 架构,其中连接必须保持打开直到最后才能从数据库中检索和访问数据,称为连接架构。互联架构建立在这些类型之上 - connection
, command
,datareader
The ADO.net architecture, in which connection will be kept open only till the data retrieved from database, and later can be accessed even when connection to database is closed is called as disconnected architecture. Disconnected architecture of ADO.net is built on these types - connection
, dataadapter
, commandbuilder
and dataset
and dataview
.
ADO.net 体系结构中,连接将保持打开状态,直到从数据库中检索到数据,之后即使与数据库的连接关闭也可以访问,这种体系结构称为断开连接体系结构。ADO.net的断开的架构是建立在这些类型的- ,,和和。connection
dataadapter
commandbuilder
dataset
dataview
回答by Upendra Singh
Connected architecture:In connected model we can connect any application to database and stays connected to the database system even when it is not using any database operations. For this architecture, we use Connection
, Command
and DataReader
.
连接架构:在连接模型中,我们可以将任何应用程序连接到数据库,并保持与数据库系统的连接,即使它不使用任何数据库操作。对于此架构,我们使用Connection
、Command
和DataReader
。
Disconnected architecture:In disconnected model we connect any application to database until we call the close method. In this architecture we use DataSet
and DataAdapter
.
断开连接的架构:在断开连接的模型中,我们将任何应用程序连接到数据库,直到我们调用 close 方法。在这个架构中,我们使用DataSet
和DataAdapter
。
回答by Mukesh kala
Connected Architecture: For Every request , Hit the Database , Fetch the DATA and bring Back. you can perform only Read Operation.Connection should be always OPEN.Uses Data Reader
连接架构:对于每个请求,点击数据库,获取数据并带回。您只能执行读取操作。连接应始终为 OPEN。使用数据读取器
Dis Connected Architecture: Fetch the Entire Data at once and now perform whatever operation you want to perform. Isert / Update / Delete. No need for the connection to be always OPEN.Uses Data Set , Data Adapter
Dis Connected Architecture:立即获取整个数据,然后执行您想要执行的任何操作。插入/更新/删除。连接不需要总是 OPEN.Uses Data Set , Data Adapter