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

0

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

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

"ERROR -> 9521 exceeds the 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]

.NET POST Code

    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;
            }
        }
    }
    
asked by anonymous 09.06.2017 / 16:24

1 answer

0

I have identified that the error happened is a limitation of SqlContext.Pipe.Send ("sring")

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

By the time the problem has been solved, but if someone has some solution for sending long msgs to the SQL output, welcome.

    
09.06.2017 / 18:29