问题描述
当我把这个code:
using (var connection = new SqlConnection(connectionString))
{
var command = new SqlCommand("SELECT * FROM Table", connection);
connection.Open();
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// Do something here
}
}
}
什么内部发生什么呢?这是如何工作在网络层面?这将使新一轮的旅行数据库中为每个调用读
或有内部实现任一批次读?
what happens internally? How does this work on a network level? Will it make a new round trip to database for each call to Read
or is there any batch read implemented internally?
我这么问是因为我刚才读的ODP.NET提供 FETCHSIZE
这两个属性的OracleCommand
和 OracleDataReader
我的理解为多少记录应当由单一的往返到数据库ploaded $ P $的定义。我不知道如果SQL Server的作品以类似的方式,如果有哪个地方可以配置一些类似的行为。我没有找到的SqlCommand
, SqlDataReader的
或的CommandBehavior $ C任何此类配置$ C>。
I'm asking because I just read that ODP.NET provides FetchSize
property in both OracleCommand
and OracleDataReader
which I understand as definition of how many records should be preloaded by single round trip to the database. I wonder if SQL Server works in similar fashion and if there is some similar behavior which can be configured somewhere. I didn't find any such configuration in SqlCommand
, SqlDataReader
or CommandBehavior
.
推荐答案
将数据从SQL Server传输到客户端在SqlConnection.PacketSize物业规模的数据包。如果您的客户端无法读取的结果足够快的网络卡上的缓冲得到填补,该协议检测到这一点,并停止接收这反过来又使SQL Server的网卡发送缓冲区已满,停止发送的任何和所有的数据。如果你想深入到protocl水平,那么请查看 TDS协议型。
the data is streamed from sql server to the client in the packets of the size in SqlConnection.PacketSize property. If your client can't read results fast enough the buffer on the network card gets filled up, the protocol detects this and stops receiving which in turn makes sql server's network card send buffer full and it stops sending any and all data. if you want to go down to the protocl level then check out TDS protcol.
这篇关于如何从SQL Server取数据,以SqlDataReader的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!