gpt4 book ai didi

sql-server - SQL Server : Could not find type in the assembly

转载 作者:行者123 更新时间:2023-12-01 18:37:08 31 4
gpt4 key购买 nike

假设程序集 dll:

using Microsoft.SqlServer.Server;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System;
using System.Text;

namespace CLRFunctions
{
public class T
{
[SqlFunction(DataAccess = DataAccessKind.Read)]
public static String NormalizeString(String s, String normalizationForm)
{
NormalizationForm form = NormalizationForm.FormC;

if (String.Equals(f, "FormD", StringComparison.OrdinalIgnoreCase))
form = NormalizationForm.FormD;

return = s.Normalize(form);
}
}
}

注意:将程序集定位到 .NET 3.5,因为 SQL Server 不支持 .NET 4.0

将程序集复制到某个位置,并且“创建”程序集工作正常:

CREATE ASSEMBLY CLRFunctions FROM 'c:\Program Files\My App\CLRFunctions.dll';

注意:然后启用CLR功能,否则是broken by default :

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO

创建用户定义函数失败:

CREATE FUNCTION NormalizeString(@s nvarchar(max), @normalizationForm varchar(50)) 
RETURNS nvarchar(max)
AS EXTERNAL NAME CLRFunctions.T.NormalizeString

失败并出现错误:

Msg 6505, Level 16, State 2, Procedure NormalizeString, Line 1
Could not find Type 'T' in assembly 'CLRFunctions'.

为什么 SQL Server 在程序集 CLRFunctions 中找不到类型 T

enter image description here

注意:为什么是TCause Microsoft did.

最佳答案

尝试

CREATE FUNCTION NormalizeString(@s nvarchar(max), 
@normalizationForm nvarchar(50))
RETURNS nvarchar(max)
AS EXTERNAL NAME CLRFunctions.[CLRFunctions.T].NormalizeString

关于sql-server - SQL Server : Could not find type in the assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7823488/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com