8

While writing a CLR function Sql Server can we use namespaces ?

namespace SomeName1.SomeName2
{
   public static class SomeClass
   {
       [SqlFunction]
       public static SqlString SomeMethod(SqlString input)
       {
          // ....
       }
   }
}

If so, then how do we call this function from SqlServer. In other words how do we call CLR functions from SQL Server with namespaces?

1 Answer 1

7

Yes, you absolutely can:

CREATE FUNCTION SomeMethod(@input VarChar(200))
RETURNS VarChar(200) WITH EXECUTE AS CALLER AS

EXTERNAL NAME [SomeName1.SomeName2].[SomeName1.SomeName2.SomeClass.SomeMethod]

Where [SomeName1.SomeName2] in the first part is the assembly as named in SQL Server, and the rest ([SomeName1.SomeName2.SomeClass.SomeMethod]) is the fully qualified function name, including the namespace.

Incidentally, if you deploy from Visual Studio it handles a lot of this for you.

Sign up to request clarification or add additional context in comments.

4 Comments

I just figured that out. I was about to answer that. [AssemblyName][Namespace.Class].[Method]. Thanks !
It would actually be [AssemlyName] then the rest goes as [SomeName1.SomeName2.SomeClass].[SomeMethod]
Correct. I'm assuming your assembly name follows that of the namespace being defined here.
@Debjit - just a typo correction to your comment: [AssemblyName].[Namespace.Class].[Method]. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.