【问题标题】:CLR function Unsupported typeCLR 函数 不支持的类型
【发布时间】:2015-05-27 20:22:40
【问题描述】:

以下CLR函数的构建会在自动生成的SQL中得到如下错误/* Error: Unsupported type. */。哪种类型导致了问题?以MSDN文档https://msdn.microsoft.com/en-us/library/ms131103.aspx为例,创建了Clr函数。

--------------------------------------------------------------------------------
--     This code was generated by a tool.
--
--     Changes to this file may cause incorrect behavior and will be lost if
--     the code is regenerated.
--------------------------------------------------------------------------------

CREATE FUNCTION [dbo].[InitMethod] (@path [nvarchar](MAX), @pattern [nvarchar](MAX), @recursive [bit])
RETURNS /* Error: Unsupported type. */
AS EXTERNAL NAME [ListFiles].[FileList].[InitMethod];

以下是C#代码。

public class FileInf
{
    public string Name { get; set; }
    public DateTime LastWriteTime { get; set; }
    public long Length { get; set; }
    public bool IsFile { get; set; }
};

[SqlFunction(FillRowMethodName = "FillRow")]
public static IEnumerable InitMethod(string path, string pattern, bool recursive)
{
    var dir = new DirectoryInfo(path);
    var files = dir.GetFiles(pattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
    foreach (var f in files)
    {
        yield return new FileInf
        {
            Name = f.Name,
            LastWriteTime = f.LastWriteTime,
            Length = f.Length,
            IsFile = (f.Attributes & FileAttributes.Directory) == FileAttributes.Directory ? false : true
        };
    }
}

public static void FillRow(Object obj, 
  out SqlChars name, 
  out SqlDateTime lastWriteTime, 
  out SqlInt64 Length, 
  out SqlBoolean isFile)
{
    var fileInfo = (FileInf)obj;
    name = new SqlChars(fileInfo.Name);
    lastWriteTime = new SqlDateTime(fileInfo.LastWriteTime);
    Length = new SqlInt64(fileInfo.Length);
    isFile = new SqlBoolean(fileInfo.IsFile);
}

【问题讨论】:

  • 你能发布你得到的确切错误吗?编号、严重性、状态、消息。
  • 错误嵌入在visual studio中生成的代码中(问题中代码的第一块)。然后在AS下出现错误,因为没有body。
  • 看起来 C# 正在返回 4 个输出,而函数仅设置为 3。是吗?

标签: sql-server sqlclr


【解决方案1】:

将您的属性更改为[SqlFunction(FillRowMethodName = "FillRow", TableDefinition = "[name] VARCHAR(MAX),[lastWriteTime] DATETIME2(7),[Length] BIGINT, [isFile] BIT")]

VS 2012 SSDT build CLR with IEnumerable failing on generated syntax

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多