Reputation: 97
First attempt at a CLR Integration, so I can use Regex tools.
I create the assembly:
CREATE ASSEMBLY SQLRegexTools
FROM 'D:\CODE\SQLRegexTools\SQLRegexTools\bin\Release\SQLRegexTools.dll'
This succeeds, and the assembly appears in SELECT @ FROM sys.assemblies.
But there are no records returned to SELECT * FROM sys.Assembly_modules.
And when I try to CREATE FUNCTION to call one of the methods,
CREATE FUNCTION RegExMatch(@pattern varchar(max)
, @SearchIn varchar(max)
, @options int)
RETURNS varchar
EXTERNAL NAME SQLRegexTools.Functions.RegExMatch
I get an error 'Msg 6505, Could not find Type "Functions" in assembly 'SQLRegexTools.'
The class name of the VB module is "Functions". Why is this called a type in the error, and why might I not be seeing anything in the modules?
Upvotes: 2
Views: 572
Reputation: 97
That hits the answer Joey. Thank you.
There are several gotchas in this process I learned after much sleuthing and testing. They are often buried in long posts about the entire process, I will summarize here:
Example:
1 2 3 4
[SQLRegexToolsASM].[SQLRegexToolsNS.RegexFunctionsClass].RegExMatch
assembly.[rootnamespace.namespace.namespace].classname.methodname”
This is the Class Name you assigned to the class, maybe like this
Public Class RegexFunctionsClass
The name of the method defined in your VB or C# assembly.
Upvotes: 1
Reputation: 670
This error occurs when SQL Server is unable to resolve the name as provided. Try the snippet below to see if this resolves the issue.
CREATE FUNCTION RegExMatch(@pattern varchar(max)
, @SearchIn varchar(max)
, @options int)
RETURNS varchar
AS EXTERNAL NAME SQLRegexTools.[Functions].RegExMatch
The resolution of individual functions/methods for accessing native code is relatively indistinguishable from a multipart object name (e.g. a type).
An additional note is that native code that utilizing nested namespaces must fully qualify nested namespaces within the same pair of quotes. For example, if RegExMatch
were located at SQLRegexTools.A.B.C.RegExMatch
, you would reference this as SQLRegexTools.[A.B.C].RegExMatch
when using it with EXTERNAL NAME
in SQL Server.
Upvotes: 2