Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:23:08+00:00 2026-06-04T05:23:08+00:00

I have been trying to find the answer to this simple question – but

  • 0

I have been trying to find the answer to this simple question – but so far couldn’t figure it out.

Let say I have MyDb.sqlproj, with various sql content (sprocs, views, trigger, etc).

I have added a new UDF through Add-> New item -> SQL CLR C#, User Defined Function.

For example:

namespace MyNameSpace
{
 public class MyClass
 {
    [SqlFunction(DataAccess = DataAccessKind.Read)]
    //I use different attributes here, but it doesn't matter
    public static int Method1()
    {
       return 0;
    }
 }
}

In MyDb.sqlproj Properties, SQLCLR tab MyDb is the name of assembly and default namespace

In my sql code I call the clr method using EXTERNAL NAME:

CREATE PROCEDURE ClrMethod1
  RETURNS [int] WITH EXECUTE AS CALLER
AS EXTERNAL NAME [MyDb].[MyNamespace.MyClass].[Method1]

I seem to tried everything to get the last line to compile. It cannot resolve the reference and get:

SQL71501: Function: [name of my sql function] has an unresolved
reference to Assembly [MyDb]

Please point me to the right way to get it working. What could I be missing?

I am using VS2010 SP1 and latest version of SSDT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:23:10+00:00Added an answer on June 4, 2026 at 5:23 am

    You must add your compiled DLL containing your CLR code as a Reference. So under your MyDb SSDT project->References(right click)->Add Reference, browse to the DLL.

    You could probably get away with referencing the project instead of the DLL if you had the CLR(class library) project in the same solution, but in my case I am referencing a DLL(compiled for a seperate solution).

    As far as the format of the AS EXTERNAL NAME line:

    AS EXTERNAL NAME [AssemblyName].[ClassName].[FunctionName]

    Note: For CLR objects I remove the namespaces from around my classes/code just to simplify things, because this step is usually the most problematic. It is easy to confuse the AssmeblyName/DLL Name/Namespace. The AssemblyName is found in your CLR class library project by accessing the Project Properties->Application->”Assembly Name:”. I would remove any non alpha-numeric/spaces from it just to simplify the name and rule out that as a problem.

    So I would try that, and once you get that working, if you really want namespaces, then you can add the namespace and figure out the syntax from there, and at least you know the other parts are correct.


    Ok reallized that you have a *.cs file actually inside the same SSDT project. so in that case if your code is this:

    CS file:

    public partial class UserDefinedFunctions
    {
        [Microsoft.SqlServer.Server.SqlFunction]
        public static SqlString SqlFunction1()
        {
            // Put your code here
            return new SqlString (string.Empty);
        }
    }
    

    SQL file:

    CREATE PROCEDURE ClrMethod1
      RETURNS [int] WITH EXECUTE AS CALLER
    AS EXTERNAL NAME [MyDB].[UserDefinedFunctions].[SqlFunction1]
    

    This compiles for me. Note: Again no namespace was used. When I did Add New Item… the generated code did not come with a namespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking around for an answer to my question but couldn't find
Been trying to google an answer but cant seem to find anything, I have
this seems like such a simple problem but I have been unable to find
I've been trying to find the answer to this question here. Several people seem
Been trying to find an answer to this but can't seem to get my
I know this is a very simple question but I have been struggling with
Simple question (probably), but I'm buggered if I can find an answer... I have
I've been trying got find this answer, and maybe it's too simple... In rails,
I have been trying to find out why the following lines of code do
I have been trying to find some resource on this topic for a while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.