为什么 t-sql 在我的程序集中找不到我的函数? [英] Why can't t-sql find my function in my assembly?
问题描述
我正在尝试使用 .NET CLR 创建存储过程.我成功地将以下代码编译成 .NET 3.5 DLL.
I am trying to create a stored procedure using the .NET CLR. I successfully compiled the following code into a .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
然后我使用以下代码成功地将它添加为程序集:
I then successfully added it as an assembly using this code:
create assembly
LevenshteinLibrary
from 'Path\LevenshteinLibrary.dll'
但是当我用这段代码创建过程时
But when I got to create the procedure with this code
create procedure testCLR(@s1 nvarchar(1000), @s2 nvarchar(1000))
as external NAME LevenshteinLibrary.LevenshteinerAndSoundexer.getLevenshteinDistance
我收到错误
"在程序集中找不到类型 'LevenshteinLibrary''LevenshteinLibrary'"
"Could not find Type 'LevenshteinLibrary' in assembly 'LevenshteinLibrary'"
为什么它不能看到"这个函数?
Why can't it "see" thefunction?
这是我在 ILSpy 中检查 DLL 时发生的情况:
Here is what happens when I examine the DLL in ILSpy:
这是我展开库时的样子
推荐答案
根据您上传的图片,您的课程 LevenshteinerAndSoundexer
位于命名空间 LevenshteinLibrary
下.因此,在定义要使用的类时,您需要包含类的命名空间(在方括号内,以免混淆解析器):
According to the image you uploader your class LevenshteinerAndSoundexer
is under the namespace LevenshteinLibrary
. Therefor you need to include the namespace of the class (inside square brackets so it does not confuse the parser) when defining which class to use:
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)-/
这篇关于为什么 t-sql 在我的程序集中找不到我的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!