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 6227295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:11:22+00:00 2026-05-24T09:11:22+00:00

Suppose I have a static class in C#: public static class Math { [Microsoft.SqlServer.Server.SqlFunction]

  • 0

Suppose I have a static class in C#:

public static class Math
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static int Add(int a, int b)
    {
        return a + b;
    }


    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void Void(int a, int b)
    {
    }

    static void Main(string[] args)
    {
    }

}

I know by @faester´s answer that to use this function in SQL we do:

 EXEC SP_CONFIGURE 'clr enabled', 1
    GO
    RECONFIGURE
    GO
    -- CONSIDER: DROP ASSEMBLY SqlClr
    GO
    CREATE ASSEMBLY SqlClr 
    FROM 'pathtoassembly'
    WITH PERMISSION_SET = SAFE;
    GO
    SELECT * FROM sys.assemblies
    GO
    CREATE FUNCTION [MathAdd] (@a int, @b int)
    RETURNS INT 
    AS EXTERNAL NAME [SqlClr].Math.[Add]
    GO 
    CREATE PROCEDURE [Void] @a INT, @b INT
    AS EXTERNAL NAME [SqlClr].Math.[Void]
    GO 
    SELECT dbo.MathAdd (1, 2)
    EXEC void 1, 2

To do this example first I added a main in the c# file

using System;
using System.Collections.Generic;
using System.Text;

public static class Math
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static int Add(int a, int b)
    {
        return a + b;
    }


    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void Void(int a, int b)
    {
    }

    static void Main(string[] args)
    {
    }

}

So, when I execute the SQL code… What path do I add. I was doing:

CREATE ASSEMBLY SqlClr 
    FROM 'C:\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe'
    WITH PERMISSION_SET = SAFE;
    GO

Obiously I must not add the .exe, so tried with the sln file and the cs file but can not get it to work…

I am getting the following, error:

Configuration option ‘clr enabled’ changed from 1 to 1. Run the
RECONFIGURE statement to install. Msg 6501, Level 16, State 7, Line 1
CREATE ASSEMBLY failed because it could not open the physical file
“C:\Visual Studio
2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe”:
5(Acces denied.).

My question besides what to put in the path, is about how to build the c# code, do I only built it like any other program, do I add something else…

  • What is it mising?
  • 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-05-24T09:11:22+00:00Added an answer on May 24, 2026 at 9:11 am

    I would suspect that it does’t like the console app…

    For a walkthrough see http://www.setfocus.com/technicalarticles/articles/clrfunctionforsqlserver.aspx

    Some interesting resources see http://msdn.microsoft.com/en-us/library/w2kae45k.aspx

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

Sidebar

Related Questions

Suppose I have some per-class data: (AandB.h) class A { public: static Persister* getPersister();
Suppose I have a class with 2 static functions: class CommandHandler { public: static
Suppose I have this code (pseudocode) class SomeClass { class Person { public static
Suppose I have this class: public class DispatcherService<T> { private static Action<T> Dispatcher; public
Suppose I have the following hierarchy: class A { public: A() private: int aa;
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Suppose that I have a Java class with a static method, like so: class
Suppose I have the following (trivially simple) base class: public class Simple { public
Let's suppose that I have the following class which tries to be immutable public
Suppose I have a class public class Foo { public Bar Bar { get;

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.