简体   繁体   English

ADO.NET连接

[英]ADO.NET Connections

could someone explain me some of the main differences between Connection-oriented access and connectionless access in ADO.NET? 有人可以向我解释ADO.NET中面向连接的访问​​和无连接访问之间的一些主要区别吗? And for what applications are they indended for? 他们打算用于什么应用? Thanks 谢谢

Connection oriented model makes use of platform specific "data providers" such as OLEDB (namespace: System.Data.Oledb ), Microsoft SQL Server (namespace: System.Data.SqlClient ), ODBC (namespace: System.Data.Odbc ), etc. 面向连接的模型利用平台特定的“数据提供程序”,例如OLEDB(名称空间: System.Data.Oledb ),Microsoft SQL Server(名称空间: System.Data.SqlClient ),ODBC(名称空间: System.Data.Odbc )等。

When you are using these data providers your application assembly and database are tightly coupled using these data providers (that means connected every time). 使用这些数据提供程序时,您的应用程序集和数据库使用这些数据提供程序紧密耦合(这意味着每次都连接)。

Whereas in disconnected model we make you of DataSet, DataAdapter, etc. Here you can understand Dataset as a buffer and DataAdaptor as a bridge joining database and this dataset. 在断开连接的模型中,我们使用DataSet,DataAdapter等。在这里,您可以将Dataset理解为缓冲区,将DataAdaptor理解为连接数据库和该数据集的桥梁。

Once you make objects of DataAdapter(ad) and DataSet(ds) and write ad.Fill(ds) , this dataset gets its buffer (all the tables, etc.) from the database and now connection with database automatically breaks. 一旦创建了DataAdapter(ad)DataSet(ds)并写入ad.Fill(ds) ,该数据集就会从数据库中获取其缓冲区(所有表等),现在与数据库的连接会自动中断。 All the future queries gets executed on this buffer (dataset) and then automatically, this updates your database after. 将来所有的查询都将在此缓冲区(数据集)上执行,然后自动执行,这将在之后更新您的数据库。 In summary, your database is used only two times: 总之,您的数据库仅使用两次:

  1. when dataset gets its buffer; 数据集何时获得缓冲区;
  2. when updating the database takes place and rest all the time remains "Disconnected". 在更新数据库时,数据库始终保持“断开连接”状态。

Connection Oriented means : connection is exist throw out your process. 面向连接的意思是 :存在连接会抛出您的进程。 Example : using DataReader in Ado.Net you can get data as connection oriented database connection type. 示例:在Ado.Net中使用DataReader可以将数据获取为面向连接的数据库连接类型。 Connection Less means : Your connection is not available throw out your whole process. 减少连接意味着 :您的连接不可用将整个过程丢掉。 Example: using DataAdapter in Ado.Net you can get data as connection less database connection type. 示例:在Ado.Net中使用DataAdapter可以获取数据,而连接少了数据库连接类型。

In client-server model, each client creates its own database connection(con.open) at startup and releases(con.close) it when the program closes. 在客户端-服务器模型中,每个客户端在启动时都会创建自己的数据库连接(con.open),并在程序关闭时释放它(con.close)。 Although the connection is only used for a fraction of time the client holds it open. 尽管连接仅使用了一小部分时间,但客户端将其保持打开状态。 Data Readers are used in this process. 在此过程中使用数据读取器。 Data is read only in Connected Data Access Example - Phone call - we connect the call and disconnect the call Note - The server must maintain a separate, live connection for each client. 在“已连接的数据访问”示例中,数据是只读的-电话-我们连接呼叫并断开呼叫。注-服务器必须为每个客户端维护一个单独的实时连接。

For Disconnected Data Access(Connection less) Data Adapters manage the connection internally to fetch the data from the database, once it fetches in closes automatically. 对于断开连接的数据访问(较少连接),数据适配器在内部管理连接以从数据库中获取数据(一旦其获取自动关闭)。 so we wont write any con.open or con.close steps separately(manually). 因此,我们不会(手动)单独编写任何con.open或con.close步骤。 Data Adapters are used for this process. 数据适配器用于此过程。 Example - Email Data can be manipulated such as insert, update. 示例-可以操纵电子邮件数据,例如插入,更新。

Connection-Oriented As soon as you Open the connection using ConnectionObject.Open() the connection will always open until your close in manually using Close(). 面向连接只要使用ConnectionObject.Open()打开连接,连接就会一直打开,直到使用Close()手动关闭为止。 Components mainly used are: 主要使用的组件有:

  1. Connection 连接
  2. Command 命令
  3. DataReader 数据读取器

Connection-less Data Adapter is used to Open and Close the connection. 无连接数据适配器用于打开和关闭连接。 It ensures whether the data reached the dataset and the connection will be closed automatically. 它确保数据是否到达数据集,并且连接将自动关闭。 All your DML operation took place in dataset. 您所有的DML操作都在数据集中进行。 If your perform any DML operation automatically Data Adapter opens the connection and update the data into the database and close the connection later on. 如果您自动执行任何DML操作,则数据适配器会打开连接并将数据更新到数据库中,然后稍后关闭连接。 Component mainly used are: 主要使用的组件有:

  1. Connection 连接
  2. Data Adapter 数据适配器
  3. DataSet 数据集

ADO.NET is framework for Database operation provided in .NET Framework.There are 2 sets of object ADO.NET是.NET Framework中提供的数据库操作框架。有两套对象

1)connection oriented - Those object that makes the DB connection like adaptor,connection,etc 1)面向连接-进行DB连接的对象,例如适配器,连接等

2) connectionless -those object that stores data offline like Datatable,data colum, etc.They are very powerful not only u can store data but create relationship, query office , etc 2)无连接-那些离线存储数据的对象,例如Datatable,data colum等,它们非常强大,不仅可以存储数据,还可以创建关系,查询办公室等

When U make normal DB operation we use connection objects and use connectionless object to store the result set. 当U进行正常的数据库操作时,我们将使用连接对象和无连接对象来存储结果集。

I suggest you read the documentation for more details. 我建议您阅读文档以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM