You should add your compiled DLL containing your CLR code as a reference. So, in the framework of the MyDb project SSDT-> Links (right click) → Add Link, go to the DLL.
You will probably be able to access the project instead of the DLL if you had the CLR project (class library) in the same solution, but in my case I refer to the DLL (compiled for a separate solution).
Regarding the format of the string AS EXTERNAL NAME
:
AS EXTERNAL NAME [AssemblyName].[ClassName].[FunctionName]
Note. . For CLR objects, I remove namespaces from my classes / code just for simplification, because this step is usually the most problematic. It's easy to confuse the name AssemblyName / DLL Name / Namespace. AssemblyName is in your CLR class library project by accessing Project Properties → Application → "Assembly Name:". I would remove any alpha-numeric / spaces from it to simplify the name and eliminate this as a problem.
So, I would try this, and once you get this working, if you really want a namespace, then you can add a namespace and figure out the syntax from there, and at least you know that the other parts are correct.
Good thing you have the * .cs file actually inside the same SSDT project. so in this case, if your code is this:
CS file:
public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString SqlFunction1() {
SQL file:
CREATE PROCEDURE ClrMethod1 RETURNS [int] WITH EXECUTE AS CALLER AS EXTERNAL NAME [MyDB].[UserDefinedFunctions].[SqlFunction1]
This compiles for me. Note: The namespace was not used again. When I added a new element ... the generated code did not come with a namespace.
source share