0

i want to create a CLR function, i created a normal class library file and coded as below, i dont want to use SqlServerProject, as i cannot find some classes there.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Types;

    namespace ClassLibrary1
    {
        public partial class Class1
        {
            [Microsoft.SqlServer.Server.SqlFunction]
            public static SqlString GetPassword(SqlString Value)
            {
                return Value;
            }
        }
    }

i compiled the code and created assembly from sqlserver like this

CREATE ASSEMBLY ASSEM
authorization dbo
FROM 'E:\NBM Sites\tvt.stage.asentechdev1.com\ClassLibrary1.dll' WITH PERMISSION_SET = SAFE;

and created a function as below

CREATE FUNCTION SampleFunc
(   
    @value nvarchar(max)
)
RETURNS nvarchar(max) with execute as caller
AS
    External Name ASSEM.Class1.GetPassword
GO

but the above create function threw an error saying.

Could not find Type 'Class1' in assembly 'ClassLibrary1'.

i dont understand, why the class1 is not recognised, as also i have made it public. Please any one help me for it.

1 Answer 1

4

You are missing the namespace that your class is in (ClassLibrary1). So the correct create function statement is:

CREATE FUNCTION SampleFunc
(   
  @value nvarchar(max)
)
RETURNS nvarchar(max) with execute as caller
AS
  External Name [ASSEM].[ClassLibrary1.Class1].[GetPassword]
GO
Sign up to request clarification or add additional context in comments.

Comments

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.