gpt4 book ai didi

.net - 为什么 t-sql 在我的程序集中找不到我的函数?

转载 作者:行者123 更新时间:2023-12-02 00:09:02 24 4
gpt4 key购买 nike

我正在尝试使用 .NET CLR 创建存储过程。我成功地将以下代码编译成.NET 3.5 DLL。

Imports System.Math
Imports System.Text.RegularExpressions
Imports Microsoft.SqlServer.Server

Partial Public Class LevenshteinerAndSoundexer

<SqlProcedure()> _
Public Shared Function getLevenshteinDistance(ByVal string1 As String, ByVal String2 As String) As Integer

然后我使用以下代码成功地将它添加为程序集:

create assembly
LevenshteinLibrary
from 'Path\LevenshteinLibrary.dll'

但是当我用这段代码创建过程时

create procedure testCLR(@s1 nvarchar(1000), @s2 nvarchar(1000))
as external NAME LevenshteinLibrary.LevenshteinerAndSoundexer.getLevenshteinDistance

我得到了错误

"Could not find Type 'LevenshteinLibrary' in assembly 'LevenshteinLibrary'"

为什么它不能“看到”函数?

这是我在 ILSpy 中检查 DLL 时发生的情况:

enter image description here

这是我扩展库时的样子

enter image description here

最佳答案

根据您上传的图片,您的类(class) LevenshteinerAndSoundexer 位于命名空间 LevenshteinLibrary 下。因此,在定义要使用的类时,您需要包括类的 namespace (在方括号内,以免混淆解析器):

create procedure testCLR(@s1 nvarchar(1000), @s2 nvarchar(1000))
as external NAME LevenshteinLibrary.[LevenshteinLibrary.LevenshteinerAndSoundexer].getLevenshteinDistance
-- Name of object in SQL --^ ^ Name of function in class --^
-- Full name of class (including namespace)-/

关于.net - 为什么 t-sql 在我的程序集中找不到我的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16617283/

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