我正在尝试使用SqlDataReader将SQL表中的BLOB数据读入变量。
奇怪的是,这个异常在大约2800行之后发生每次。我已经排除了有问题的行,但显然这不是由于行本身,而是由于行(或字节)的总量。
例外:
A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)
我的代码:
string command = string.Format("SELECT * FROM (select *, ntile({0}) over(order by Id) as SplitNumber from BLOB) T1 WHERE SplitNumber = {1}", _maxThreadCount - (Environment.ProcessorCount * 2) + 1, splitNumber);
using (SqlConnection sqlConnection = new SqlConnection(SourceConnectionString))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = new SqlCommand(command, sqlConnection))
{
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
if (sqlDataReader.HasRows)
{
while (sqlDataReader.Read())
{
try
{
byte[] blob = (byte[])sqlDataReader["Blob"];
[.......]
异常发生在byte[] blob = (byte[])sqlDataReader["Blob"];
上,我无法想象为什么会发生这种情况。
有什么想法吗?