CLR UDF 返回 Varbinary(MAX) [英] CLR UDF returning Varbinary(MAX)

查看:48
本文介绍了CLR UDF 返回 Varbinary(MAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL CLR 用户定义函数是否可以返回数据类型 varbinary(MAX)?

Is it possible for a SQL CLR User-Defined Function to return the data type varbinary(MAX)?

在它提到的文档中:

标量值函数返回的输入参数和类型可以是 SQL Server 支持的任何标量数据类型,但 rowversion、text、ntext、image、timestamp、table 或 cursor 除外."- 他们没有提到 varbinary,但我不确定...

"The input parameters and the type returned from a scalar-valued function can be any of the scalar data types supported by SQL Server, except rowversion, text, ntext, image, timestamp, table, or cursor." - they don't mention varbinary, but I'm not sure...

我有一些来自 .NET 端的字节数组数据,我需要从 CLR 返回到 SQL Server,并且我试图避免使用来自存储过程的输出参数(这就是我现在正在测试中).

I have some byte-array data from the .NET side that I need to return to SQL Server from the CLR, and I'm trying to avoid having to do it with an output parameter from a stored procedure (this is how I have it working in test now).

谢谢!

推荐答案

如果您将其定义为返回一个 SqlBytes 数据类型,这应该正确映射到 SQL Server 中的 varbinary(MAX).

If you define it as returning a SqlBytes data type, this should correctly map to varbinary(MAX) in SQL Server.

[SqlFunction]
public static SqlBytes Function1()
{
    return new SqlBytes(Encoding.UTF8.GetBytes("Hello world."));
}

虽然您也可以使用 SqlBinary 数据类型,如果您通过 Visual Studio 部署,它将映射到 varbinary(8000) 而不是 varbinary(MAX).

Whilst you can also use the SqlBinary data type, if you deploy via Visual Studio, it will be mapped onto varbinary(8000) rather than varbinary(MAX).

这篇关于CLR UDF 返回 Varbinary(MAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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