I've been banging my head on this one for a while now, though only now did I finally sit down to figure out to solve it. I have (inherited from another dev) a CRL SQL Stored Procedure which outputs a long string. The signature looks like:
public static void DoSomething(SqlString input,out SqlString output)
When output was long, an exception would be thrown similar to:
System.Data.SqlServer.TruncationException: Trying to convert return value or output parameter of size 28726 bytes to a T-SQL type with a smaller size limit of 8000 bytes.
Now you'd think that SqlString would map to varchar(max), if possible, but this is not the case. (I should also mention that the output is limited to 4000 bytes when using nvarchar).
The solution is to use SqlChars instead of SqlString - somewhere behind the scenes, this will get translated back to nvarchar, so the following will work:
DECLARE @output varchar(max)
EXEC DoSomething 'Loren Ipsum Dolar', @output output
SELECT @output
Of course you will have to convert your string to the SqlChars type before returning:
char[] chars = "Some String".ToCharArray();
output = new SqlChars(chars);
Hope this helps!
0 comments:
Post a Comment