snippetsqlMinor
How do I create a CLR UDF with external name specifying namespace, class, and subclass?
Viewed 0 times
specifyingclasscreatewithclrsubclassnamehowandexternal
Problem
I am creating a CLR UDF using external name and second level nested class names seem not to be permitted. Is this the case? When using the following syntax and including a first level class name and associated method, I am able to bind a UDF to the method, but not if I included additional subclass levels.
Thanks
CREATE FUNCTION [dbo].[udf_test](@variable [nvarchar](MAX))
RETURNS [nvarchar](MAX) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [assembly].[ns.first.second].[method]
GOThanks
Solution
As far as I can tell (I did some testing of my own), this is not supported.
The documentation hints at this:
If the class has a namespace-qualified name that uses a period (.) to separate namespace parts, ...
Since there's no mention of a class-qualified name, I'm assuming SQL Server will traverse the hierarchy only by namespaces, with the last name being the class itself. There wasn't any way I could find to delimit the namespace and class name portions of the fully-qualified class name either.
What I wonder, though, is why your code is structured this way? The method you need to specify must be static, so nesting it within an extra class scope seems like you're (ab)using a class in place of a namespace.
The documentation hints at this:
If the class has a namespace-qualified name that uses a period (.) to separate namespace parts, ...
Since there's no mention of a class-qualified name, I'm assuming SQL Server will traverse the hierarchy only by namespaces, with the last name being the class itself. There wasn't any way I could find to delimit the namespace and class name portions of the fully-qualified class name either.
What I wonder, though, is why your code is structured this way? The method you need to specify must be static, so nesting it within an extra class scope seems like you're (ab)using a class in place of a namespace.
Context
StackExchange Database Administrators Q#35384, answer score: 2
Revisions (0)
No revisions yet.