在完成读取之前关闭 ODBCDataReader,ODBCData Reader 需要很长时间才能关闭
我正在运行一个使用 ODBCDataReader 调用 SQL 查询的代码。查询的结果将放入电子邮件附件中并邮寄给用户。如您所知,邮件服务器对可以发送的数据量有限制。所以我所做的就是将附件限制为一定大小。这会导致 ODBCDataReader 在到达查询末尾之前提前完成
while (_ODBCConn.Data.Read() && AttachmentFileSize < MaxAttachmentSize)
{
//Write to file attachment
//Obtain AttahmentFileSize
}
不幸的是,当我运行下一组代码来关闭读取器时,它最终花费了很长时间
if (_reader != null)
{
_reader.Close();
}
有人知道如何使读取器更快地关闭吗?
I'm running a code which calls an SQL query using ODBCDataReader. The result of the query is to be put into an email attachment and mailed to the user. As you know, mail servers have a llimit to how much data can be sent. So what I did was to set a limit to the attachment to a certain size. This causes the ODBCDataReader to finish early before reaching the end of the query
while (_ODBCConn.Data.Read() && AttachmentFileSize < MaxAttachmentSize)
{
//Write to file attachment
//Obtain AttahmentFileSize
}
Unfortunately when I run the next set of code to close the reader, it ends up taking a long time
if (_reader != null)
{
_reader.Close();
}
Does anybody know how to make the reader close faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我并不是回避你的问题,但我怀疑你能对读者关闭所需的时间采取任何措施。但是,如果 close 命令阻止了一些需要稍后运行的时间敏感代码,您可以在不同的线程上调用该行。我会确保在再次使用读取器之前检查它的状态,因为线程可能需要一些时间来执行。
I'm not dodging your question, but I doubt you can do anything about the amount of time it takes for the reader to close. However, if the close command is holding up some time-sensitive code that needs to run afterward you could call that line on a different thread. I would make sure to check the status of the reader before you use it again since the thread can take some time to execute.