我有一些生成小报告文件的代码.对于集合中的每个文件,执行存储过程以通过XML阅读器获取数据(它是一个非常大的结果集).当我创造了这一切,并逐步完成它,一切都很好.生成文件,没有错误.
该库通过远程处理调用,并通过IIS托管.当我部署已编译的库并调用它时,它能够生成一些报告,但随后会抛出一个Thread Abort Exception.如果我将调试器附加到asp工作进程,并逐步执行代码,我没有问题.
看到这种失败是非常一致的,我寻找相似之处并发现失败发生在不同的报告上,但似乎发生在大约相同的时间点.
这让我认为这是一个超时设置,调试器重写,我做了一些粗略的整个过程时间(不是单一的失败代码),它似乎在大约200秒后失败. web.config executionTimeout设置为600分钟(足够高).此服务器应用程序还有其他部分需要COM事务(2分钟超时),但这不是其中之一.我不知道它可能达到的超时时间(大约200秒大关).
SQL Connection超时默认保留(连接成功打开),命令超时为300秒(执行命令只需12-15).
>我可能缺少任何其他超时吗?
我运行了SQL分析器,它显示结果正确返回(所有语句和RPC完成 – 没有错误).通过SSMS执行代码可提供完美的结果.
使用反射器,我钻进了SNINativeMethodWrapper,它是非托管代码的包装器,我无法看到它试图实际做什么.我只能假设(可能错误地)代码已经从SQL服务器接收到TDS,并且包装器试图获得与数据包关联的连接,但它不能.
>有谁知道这个包装器应该做什么?
>有没有办法跟踪/调试此代码以找出导致失败的原因?
我尝试使用不同的方法(ExecScalar,DataAdapter),但它们都在内部使用ExecuteReader.
我尝试禁用连接池并强制客户端使用与服务器相同的数据包大小.
>有没有人对是什么原因产生任何想法,或者我可以做些什么来隔离并尝试纠正问题?
这是生成异常的调用代码.
Private Function GetDataAsXmlDoc(ByVal cmd As SqlClient.SqlCommand) As XmlDocument Dim _xmlDoc As XmlDocument Using _connection As New SqlClient.SqlConnection(GetConnectionString()) Logging.DebugEvent.Raise(Me.GetType.Namespace,Reflection.MethodBase.GetCurrentMethod().Name,_ "No cached data found or used. Getting data for report from the database using SQL connection.") Dim _xmlReader As XmlReader 'DataAdapter,ExecuteScalar,ExecuteXmlReader all use ExecuteReader internally and suffer the same problem.' 'If you dont believe me,reflect it or look at one of the blowed up stack traces. ' '_connection.ConnectionString += ";Pooling=false;"' 'This has no effect on the ThreadAbort.' cmd.Connection = _connection cmd.CommandTimeout = 300 _connection.Open() Logging.DebugEvent.Log(String.Format("Connection opened,using packet size of {0}.",_connection.PacketSize)) _xmlReader = cmd.ExecuteXmlReader() 'Thread aborts in here' Logging.DebugEvent.Raise(Me.GetType.Namespace,_ "Report data recieved from database") _xmlDoc = New XmlDocument() _xmlDoc.Load(_xmlReader) _xmlReader.Close() End Using Return _xmlDoc End Function
堆
Exception String - System.Threading.ThreadAbortException: Thread was being aborted. at SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr packet) at System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr packet,UInt32 error) at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult,TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket() at System.Data.SqlClient.TdsParserStateObject.ReadBuffer() at System.Data.SqlClient.TdsParserStateObject.ReadByte() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,Boolean returnStream,Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,String method,DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,String method) at System.Data.SqlClient.SqlCommand.ExecuteXmlReader()...
解决方法
Logging.DebugEvent.Raise(Me.GetType.Namespace,_ "Report data recieved from database")
这是对应用程序块(MS企业库)的调用,用于将事件记录到平面文件(在本例中)或事件日志.
这个,在ExecuteXMLReader()和XML文档中读者的实际用法之间,有时会严重失败,导致整个线程中止.我将行移到了_xmlReader.Close()之后,它解决了这个问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。