在 .Net 中创建用户定义的 CLR 函数
我想创建一个 CLR 函数,我创建了一个普通的类库文件并编码如下,我不想使用 SqlServerProject,因为我在那里找不到一些类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Types;
namespace ClassLibrary1
{
public partial class Class1
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString GetPassword(SqlString Value)
{
return Value;
}
}
}
我编译了代码并从 sqlserver 创建了程序集,如下所示
CREATE ASSEMBLY ASSEM
authorization dbo
FROM 'E:\NBM Sites\tvt.stage.asentechdev1.com\ClassLibrary1.dll' WITH PERMISSION_SET = SAFE;
,并创建了一个函数,如下所示
CREATE FUNCTION SampleFunc
(
@value nvarchar(max)
)
RETURNS nvarchar(max) with execute as caller
AS
External Name ASSEM.Class1.GetPassword
GO
,但上面的创建函数抛出了一个错误。
Could not find Type 'Class1' in assembly 'ClassLibrary1'.
我不明白,为什么 class1 不被认可,因为我也将其公开。 请任何人帮助我。
i want to create a CLR function, i created a normal class library file and coded as below, i dont want to use SqlServerProject, as i cannot find some classes there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Types;
namespace ClassLibrary1
{
public partial class Class1
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString GetPassword(SqlString Value)
{
return Value;
}
}
}
i compiled the code and created assembly from sqlserver like this
CREATE ASSEMBLY ASSEM
authorization dbo
FROM 'E:\NBM Sites\tvt.stage.asentechdev1.com\ClassLibrary1.dll' WITH PERMISSION_SET = SAFE;
and created a function as below
CREATE FUNCTION SampleFunc
(
@value nvarchar(max)
)
RETURNS nvarchar(max) with execute as caller
AS
External Name ASSEM.Class1.GetPassword
GO
but the above create function threw an error saying.
Could not find Type 'Class1' in assembly 'ClassLibrary1'.
i dont understand, why the class1 is not recognised, as also i have made it public.
Please any one help me for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您缺少类所在的命名空间 (ClassLibrary1)。所以正确的create函数语句是:
You are missing the namespace that your class is in (ClassLibrary1). So the correct create function statement is: