简体   繁体   English

CLR存储过程线程异常

[英]CLR Stored Procedure thread exception

I have the follow code that works in an exe and even works on small xml files in the CLR but once they get larger than 10mb I get a thread abortion error. 我有以下代码可以在exe中运行,甚至可以在CLR中的小型xml文件上运行,但是一旦它们变得大于10mb,我就会收到线程中止错误。 Is there something I need to configure in SQL Server? 我需要在SQL Server中进行配置吗?

Try

    sStream = HttpRequest.GetRequestStream()
    sStream.Write(baByteArray, 0, baByteArray.Length)
    sStream.Close()
    wrWebResponse = HttpRequest.GetResponse()
    sStream = wrWebResponse.GetResponseStream()
    Dim readStream As New StreamReader(sStream, System.Text.Encoding.UTF8)
    strXmlResponse = readStream.ReadToEnd() ' Errors out here
    strXmlResponseDoc.LoadXml(strXmlResponse)
    wrWebResponse.Close()
    sStream.Close()
    readStream.Close()

Catch ex As Exception

    SqlContext.Pipe.Send(ex.ToString())
    clsE.LogError(ex.ToString())

End Try

Error message: 错误信息:

System.Threading.ThreadAbortException: Thread was being aborted.
 at System.Threading.Thread.AbortInternal()
 at System.Threading.Thread.Abort(Object stateInfo)
 at   System.Data.SqlServer.Internal.ClrLevelContext.CheckSqlAccessReturnCode(SqlAccessApiReturnCode eRc)
 at System.Data.SqlServer.Internal.ClrLevelContext.SendMessageToPipe(String message, SmiEventSink eventSink)
 at Microsoft.SqlServer.Server.SqlPipe.Send(String message)
 at MacCLR.MacClass.RequestXml(String strXmlToSend)
 at MacCLR.StoredProcedures.ProcessShippingXML_1(String iOrderNumb, String iXmlFilePath, String iXmlFileName, SqlInt32& iResult, SqlString& iResult_String)

Every object you create that implements the IDisposable interface needs to be in a Using block. 您创建的实现IDisposable接口的每个对象都必须在Using块中。 That ensures the object is cleaned up promptly, regardless of exceptions. 这样可以确保迅速清除对象,无论是否有异常。 That includes the two streams, the WebResponse, and the StreamReader. 其中包括两个流,即WebResponse和StreamReader。

This is especially critical for code that's running inside of the SQL Server process. 这对于在SQL Server进程内部运行的代码特别重要。

After putting in a using block for each of the IDisposable interfaces I was still getting an error about but it led me to realize that it is a 32 bit SQL Server installation and from what I read it handles CLR memory differently than 64-bit. 在为每个IDisposable接口放置一个using块之后,我仍然遇到错误,但是这使我意识到这是32位SQL Server安装,并且从我的阅读来看,它处理CLR内存的方式与64位不同。 Using the ;-g384 startup parameter at least bandaided the error until I can implement a more robust solution. 至少可以使用; -g384启动参数来说明错误,直到我可以实现更可靠的解决方案为止。 Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM