的SqlClient调用导致"正在中止线程在SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr的数据包)" [英] SqlClient calls causing "Thread was being aborted at SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr packet)"

查看:814
本文介绍了的SqlClient调用导致"正在中止线程在SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr的数据包)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的AP preciate任何建议,无论简单还是复杂,帮我拿这个问题隔离和解决。

我有一点code,产生小报告文件。对于集合中的每个文件,一个存储过程执行以获得通过XML阅读器(它的一个pretty的大结果集)中的数据。当我创造了这一切,并通过它加强,一切都很好。被生成的文件,没有错误。

该库是通过远程调用,并通过IIS托管。当我部署编译的库并调用它,它能够生成一些报告,但随后抛出一个线程中止异常。如果我调试器附加到ASP的工作进程,并通过code步骤,我没有问题。

看到因为这种故障​​是pretty的一致,我寻找相似之处,发现故障发生在不同的报告,但似乎发生在大约相同的时间顺序点。

这使我认为这是一个超时设置,调试器是压倒一切的,我做的整个过程(而不是单件的失败code)的一些粗略计时,似乎在失败刚过约200秒。在Web.config executionTimeout设置的600分钟(大量足够高)。还有其他部分需要COM +交易(2分钟的超时)这个服务器应用程序,但这不是其​​中之一。我很茫然,什么超时它可以打(约200秒标记)。

SQL连接超时留在默认(连接成功打开),命令超时时间为300秒(只需12-15的exec命令)。

  • 有,我可能会错过任何其他超时?

我跑SQL事件探查器,它表明结果正确返回(所有语句和RPC完成 - 没有错误)。通过SSMS执行的code提供了完美的效果。

使用反射,我钻入SNINativeMethodWrapper,其包装的非托管code,我不能看到它的努力实际上做。我只能假设(也许是错误的),该code已经收到了TDS从SQL服务器和包装器是试图让与分组相关联的连接,它不能。

  • 有谁知道这是什么包装是应该做的?
  • 有没有办法跟踪/调试此code,找出是什么原因造成的失败?

我试着用不同的方法(ExecScalar,DataAdapter的),但它们都使用的ExecuteReader内部。

我尝试禁用连接池并迫使客户端使用相同的分组大小作为服务器。

  • 在没有任何人有任何想法,是什么原因导致这一点,或者我能做些什么来隔离并试图​​纠正这个问题?

这是产生异常的调用code。

 专用功能GetDataAsXmlDoc(BYVAL CMD作为SqlClient.SqlCommand)作为的XmlDocument

    昏暗_xmlDoc作为的XmlDocument

    使用_connection作为新SqlClient.SqlConnection(GetConnectionString())

        Logging.DebugEvent.Raise(Me.GetType.Namespace,Reflection.MethodBase.GetCurrentMethod()。名称,_
                                 没有找到缓存数据或使用。使用SQL连接获取数据的报告从数据库中。)

        昏暗_xmlReader作为的XmlReader
        DataAdapter的,的ExecuteScalar,内部的ExecuteXmlReader全部使用的ExecuteReader并遭受了同样的问题。
        如果你不相信我的话,反映了它还是看的最多炸飞堆栈跟踪之一。 

        _connection.ConnectionString + =;池=假;'。'这对ThreadAbort没有影响
        cmd.Connection = _connection
        cmd.CommandTimeout = 300
        _connection.Open()

        Logging.DebugEvent.Log(的String.Format(连接打开,使用的数据包大小{0},_connection.PacketSize))

        _xmlReader = cmd.ExecuteXmlReader()线程中止这里

        Logging.DebugEvent.Raise(Me.GetType.Namespace,Reflection.MethodBase.GetCurrentMethod()。名称,_
                                 报告从数据库:收到的数据)

        _xmlDoc =新的XmlDocument()
        _xmlDoc.Load(_xmlReader)

        _xmlReader.Close()

    结束使用

  返回_xmlDoc

端功能
 

堆栈

 异常字符串 -  System.Threading.ThreadAbortException:线程已被中止。
   在SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr的数据包)
   在System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr的数据包,UInt32的误差)
   在System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult,TdsParserStateObject stateObj)
   在System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
   在System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
   在System.Data.SqlClient.TdsParserStateObject.ReadByte()
   在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
   在System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   在System.Data.SqlClient.SqlDataReader.get_MetaData()
   在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader的DS,RunBehavior runBehavior,串resetOptionsString)
   在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,布尔异步)
   在System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法,DbAsyncResult结果)
   在System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法)
   在System.Data.SqlClient.SqlCommand.ExecuteXmlReader()...
 

解决方案

我相信我已经解决了这个问题。上面的code例子中的违规行为的声明...

  Logging.DebugEvent.Raise(Me.GetType.Namespace,Reflection.MethodBase.GetCurrentMethod()。名称,_
                                 报告从数据库:收到的数据)
 

这是事件记录到平面文件(在这种情况下)或事件日志调用一个应用程序块(MS企业库)。

这个之一,在的ExecuteXmlReader()和XML文件,被有时不能严厉在阅读器的实际使用情况,造成整个螺纹中止之间。我搬到了线后, _xmlReader.Close()并花了照顾的问题。

I would really appreciate any suggestions, no matter how simple or complex, to help me get this issue isolated and resolved.

I have a bit of code that generates small report files. For each file in the collection, a stored proc is executed to get the data via XML reader (its a pretty big result set). When I created all this, and stepped through it, all is well. Files are generated, no errors.

This library is called via remoting, and is hosted via IIS. When I deploy the compiled library and call it, its able to generate some of the reports, but then throws a Thread Abort Exception. If I attach the debugger to the asp worker process, and step through the code, I have no problems.

Seeing as this failure is pretty consistent, I looked for similarities and found that the failure happens on different reports, but seems to happen at about the same chronological point.

This lead me to think that it was a timeout setting that the debugger is overriding, I did some rough timings of the overall process (not the single piece of failing code) and it seems to fail at just after about 200 seconds. The web.config executionTimeout is set for 600 minutes (plenty high enough). There are other parts to this server application that require COM+ transactions (2 minute timeout), but this is not one of them. I am at a loss as to what timeout it could be hitting (at about the 200 second mark).

The SQL Connection timeout is left at default (the connection opens successfully), the command timeout is 300 seconds (it takes only 12-15 to exec the command).

  • Is there any other timeout that I could be missing?

I ran SQL profiler, and it shows that the result is returned correctly (all statements and RPC completed - no errors). Executing the code via SSMS provides perfect results.

Using reflector, I drilled into the SNINativeMethodWrapper, and its a wrapper for unmanaged code and I cant see what its trying to actually do. I can only assume (perhaps wrongly) that the code has received the TDS from the SQL server and the wrapper is trying to get the connection associated with the packet and it cannot.

  • Does anyone know what this wrapper is supposed to do?
  • Is there any way to trace / debug this code to find out what is causing the failure?

I tried using different methods (ExecScalar, DataAdapter), but they all use ExecuteReader internally.

I tried disabling connection pooling and forcing the client to use the same packet size as the server.

  • Does anybody have any ideas as to what causes this, or what I can do to isolate and try to correct the problem?

This is the calling code where the exception is generated.

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, Reflection.MethodBase.GetCurrentMethod().Name, _
                                 "Report data recieved from database")

        _xmlDoc = New XmlDocument()
        _xmlDoc.Load(_xmlReader)

        _xmlReader.Close()

    End Using

  Return _xmlDoc

End Function

Stack

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, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteXmlReader()...

解决方案

I believe I have resolved the problem. The offending line of code in the example above was the statement...

 Logging.DebugEvent.Raise(Me.GetType.Namespace, Reflection.MethodBase.GetCurrentMethod().Name, _
                                 "Report data recieved from database")

This is a call to a Application Block (MS enterprise library) for logging events to flat files (in this case) or event logs.

This one, in between the ExecuteXMLReader() and the actual usage of the reader in the XML document, was sometimes failing harshly, causing the whole thread to abort. I moved the line to after the _xmlReader.Close() and it took care of the problem.

这篇关于的SqlClient调用导致"正在中止线程在SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr的数据包)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆