UDA生成错误,缓冲区大小不足

Nar*_*Dog 1 sql database sql-server sql-server-2005

我在SQL 2005中有一个UDA,它一直生成以下错误.我猜这很可能是由于最大字节大小为8000的限制....有什么工作我可以用来解决这个问题吗?有关在2005年避免此限制的任何建议吗?我知道2008年应该取消这些限制,但我暂时无法升级.

A .NET Framework error occurred during execution of user-defined routine or aggregate "CommaListConcatenate": 
System.Data.SqlTypes.SqlTypeException: The buffer is insufficient. Read or write operation failed.
System.Data.SqlTypes.SqlTypeException: 
   at System.Data.SqlTypes.SqlBytes.Write(Int64 offset, Byte[] buffer, Int32 offsetInBuffer, Int32 count)
   at System.Data.SqlTypes.StreamOnSqlBytes.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BinaryWriter.Write(String value)
   at TASQLCLR.CommaListConcatenate.Write(BinaryWriter w)
Run Code Online (Sandbox Code Playgroud)

Rot*_*ots 5

对于SQL 2005,您可以通过使用分隔符将一个参数转换为多个参数来解决8000字节限制.我自己不需要详细介绍,但你可以在这里找到答案:http://www.mssqltips.com/tip.asp?提示= 2016

对于SQL 2008,您需要将MaxByteSize作为-1传递.如果您尝试传递大于8000的数字,SQL将不允许您创建聚合,抱怨存在8000字节限制.如果你传入-1,它似乎解决了这个问题,并允许你创建聚合(我也测试了> 8000字节).

错误是:

"Class.Concatenate"的大小(100000)不在有效范围内.大小必须为-1或介于1和8000之间的数字.

这是VB.NET的工作类定义,在SQL 2008中支持> 8000字节.

<Serializable(), SqlUserDefinedAggregate(Format.UserDefined, 
IsInvariantToNulls:=True, 
IsInvariantToDuplicates:=False, 
IsInvariantToOrder:=False, MaxByteSize:=-1)>
<System.Runtime.InteropServices.ComVisible(False)> _
Public Class Concatenate Implements IBinarySerialize
End Class
Run Code Online (Sandbox Code Playgroud)