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

  • Home
  • SEARCH
  • 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 8348291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:38:55+00:00 2026-06-09T07:38:55+00:00

I am trying to create a simple msmq messaging application using clr stored procedure

  • 0

I am trying to create a simple msmq messaging application using clr stored procedure integrated in sql server 2008.

Followed the below steps

  1. By defualt System.Messaging reference wont be available in sql server,so created this assembly

    ALTER DATABASE [AdventureWorksLT2008] SET TRUSTWORTHY on
    create ASSEMBLY Messaging
    AUTHORIZATION dbo
    FROM ‘C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll’
    WITH PERMISSION_SET = EXTERNAL_ACCESS
    GO

2.created sql server application with a stored procedure

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Messaging;
using System.Security;

    [assembly: AllowPartiallyTrustedCallers]
    namespace CLRProcedure
    {

        public class StoredProcedure
        {
            /// <summary>
            /// Sends message to queue
            /// </summary>
            /// <param name="queue">Queue path</param>
            /// <param name="msg">Message</param>
            [SqlProcedure]

            public static void Proc_Send_Queue(SqlString queue, SqlString msg)
            {
                using (MessageQueue msgQueue = new MessageQueue(queue.ToString(), QueueAccessMode.Send))
                {
                    msgQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
                    msgQueue.Send(msg.Value);
                }
            }
         }     
     }
  1. registered that assembly in sql server
    create assembly MSMQApp from ‘E:\CCA Parctise\SqlMSMQ.dll’

SqlMSMQ.dll is the sql server applicaiton dll.

  1. create stored procedure
    create PROCEDURE [dbo].[Proc_Send_Queue]
    (@queue nvarchar,
    @msg nvarchar)
    WITH EXECUTE AS CALLER
    AS
    EXTERNAL NAME [MSMQApp].[CLRProcedure.StoredProcedure].[Proc_Send_Queue]
  2. while executing stored procedure
    USE [AdventureWorksLT2008]
    GO
    DECLARE @return_value int
    EXEC @return_value = [dbo].[Proc_Send_Queue]
    @queue = N’SampleQ’, –msmq name
    @msg = N’Simpel queue message’ — message
    SELECT ‘Return Value’ = @return_value
    GO

    throwing below error

    Msg 6522, Level 16, State 1, Procedure Proc_Send_Queue, Line 0
    A .NET Framework error occurred during execution of user-defined routine or aggregate “Proc_Send_Queue”:
    System.Security.SecurityException: That assembly does not allow partially trusted callers.
    System.Security.SecurityException:
    at CLRProcedure.StoredProcedure.Proc_Send_Queue(SqlString queue, SqlString msg)

Appreciating your help to solve this.

Thanks in advance

  • 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-09T07:38:56+00:00Added an answer on June 9, 2026 at 7:38 am

    Allowing Partially Trusted Callers states:

    We recommend that all assemblies registered in SQL Server, except
    those assemblies added to the global assembly cache, be marked with
    the AllowPartiallyTrustedCallers attribute so that assemblies loaded
    by SQL Server can access each other.

    You did exactly what the recommendation says, and you get the error. So what’s going on? See Strong named assemblies and AllowPartiallyTrustedCallers:

    When assembly B calls strong-named assembly A,

    Either A must have AllowPartiallyTrustedCallers attribute Or B must
    have unsafe (FullTrust) permission set.

    In your case ‘B’ is SqlMSMQ.dll and the strong-named ‘A’ is System.Messaging.dll. Since you cannot modify ‘A’ to have the APTC attribute, the only solution is to modify ‘B’ to be full trusted (ie. UNSAFE):

     create assembly MSMQApp from 'E:\CCA Parctise\SqlMSMQ.dll'
       with permission_set = unsafe;
    

    What is the recipient of your messages? If is another application backed by SQL Server then you have a much better alternative in Service Broker.

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

Sidebar

Related Questions

Trying to create a simple flickr application using Ruby on Rails 3.2.3, I faced
Im trying to create a simple pan and zoom app using silverlight 4, but
I am trying to create a simple program using Gstreamer to take the input
when trying to create a simple procedure in mysql 5.1.47-community it fails everytime i've
I am trying to create a simple offline application for personal-use that uses a
I'm trying to create a simple file upload form for my website. I'm using
I'm trying to create simple DER decoder - console application that just outputs content
trying to create simple package with one procedure: CREATE OR REPLACE PACKAGE PACKAGE1 AS
I`m trying to create simple QML application. I have QtSDK installed with latest QtCreator.
I'm trying to create simple ExtJs application that manages Users and User's Roles. Set

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.