CLR . NET - ERROR -> 9521 exceeds the maximum accepted message size of 4,000

Asked

Viewed 37 times

0

My code makes a webapi post from a trigger in an SP that monitors my database.

This POST works well for msgs of up to 4000 characters but above that the SP gives this error:

"ERROR -> 9521 exceeds maximum accepted message size of 4,000."

SP:

    CREATE PROCEDURE TESTE_SP_TransactionNotification
        @object_type nvarchar(20),
        @transaction_type nchar(1),
        @list_of_key_cols_tab_del nvarchar(max),
        @list_of_cols_val_tab_del nvarchar(max),
        @ErrorNumber int output,
        @ErrorDescription nvarchar(4000) output
    as EXTERNAL NAME [Xnet.Atelie.Integration.Clr].
    [Clr.StoredProcedures].[TESTE_SP_TransactionNotification]

Code POST . NET

    protected string POST([SqlFacet(MaxSize = -1)]string message, string url, string routerKey)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";

        SqlContext.Pipe.Send("Send::: " + message);

        var messageBytes = Convert.ToBase64String(Encoding.UTF8.GetBytes(message));

        var send = "{\"exchange\":\"" + this.Exchange + "\", \"routerKey\":\"" + routerKey + "\", \"content\": \"" + messageBytes + "\" }";

        SqlContext.Pipe.Send(send);

        request.ContentType = "application/json";
        request.ContentLength = Encoding.UTF8.GetBytes(send).Length;

        using (var dataStream = request.GetRequestStream())
        {
            dataStream.Write(Encoding.UTF8.GetBytes(send), 0, Encoding.UTF8.GetBytes(send).Length);
            dataStream.Close();

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                SqlContext.Pipe.Send(response.StatusDescription);

                var responseFromServer = response.StatusDescription;

                response.Close();

                SqlContext.Pipe.Send(responseFromServer);

                return responseFromServer;
            }
        }
    }

1 answer

0

I identified that the error happened this is a limitation of the Sqlcontext.Pipe.Send("Sring")

This method is responsible for sending msg to the SQL output. Nothing that would harm sending msg to the Api. So I just mentioned it and it worked.

For now the problem has been solved, but if anyone has any solution for how to send long msgs to SQL output, you are welcome.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.