bernie2436
bernie2436

Reputation: 23901

Why can't t-sql find my function in my assembly?

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

I get the error

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

Why can't it "see" thefunction?

Here is what happens when I examine the DLL in ILSpy:

enter image description here

Here is what it looks like when I expand out the library

enter image description here

Upvotes: 3

Views: 2733

Answers (1)

Scott Chamberlain
Scott Chamberlain

Reputation: 127583

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)-/

Upvotes: 3

Related Questions