I have an azure function in .net 7.0 isolated process shown below where I read the params passed on HTTPTrigger and send it as parameter to the stored procedure. But the CustomerKey value received will have = sign as it is encrypted. Sql extension throws run time exception when it sees = sign in the parameter. I have been through the below document and it says we cannot have = in params list. But how do I achieve this? Is there any work around?

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-sql-input?tabs=isolated-process&pivots=programming-language-csharp

Parameters Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format @param1=param1,@param2=param2. Neither the parameter name nor the parameter value can contain a comma (,) or an equals sign (=).

[Function("GetCustomers")]
        public static async Task<HttpResponseData>  Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "customers/{CustomerKey}/{batchsize:int}")] HttpRequestData req,
            ILogger log,
             [SqlInput(commandText: "storedprocName", commandType: System.Data.CommandType.StoredProcedure, 
                parameters: "@CustomerKey={CustomerKey},@BatchSize={batchsize}", connectionStringSetting: "SqlConnectionString")]             
                IAsyncEnumerable<customer> customers)
        { ...}

When we run the azure function, if the URL parameter has value = it results in run time exception.

System.Private.CoreLib: Exception while executing function: Functions.GetCustomers. Microsoft.Azure.WebJobs.Extensions.Sql: Parameters must be separated by "," and parameter name and parameter value must be separated by "=", i.e. "@param1=param1,@param2=param2". To specify a null value, use null, as in "@param1=null,@param2=param2".To specify an empty string as a value, simply do not add 
anything after the equals sign, as in "@param1=,@param2=param2".
1

There are 1 best solutions below

0
Pravallika KV On

enter image description here

To pass the parameters value which is containing =, you can encode the value with %3D.

Sample Code:

public class Function1
{
        [Function("Function1")]
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "function1")]
        HttpJsonBodyObj reqbody,
            [SqlInput("dbo.ToDoo",
            commandType: System.Data.CommandType.StoredProcedure,
            parameters: "@order={order},@title={title},@url={url},@completed={completed}",
            connectionStringSetting: "SqlConnectionString")]
        IEnumerable<ToDoItem> toDoItem)
        {
            return new OkObjectResult(toDoItem.FirstOrDefault());
        }
    
}

public class HttpJsonBodyObj
{
    public dynamic title
    {
        get => title;
        set
        {             
            title = value.Replace("=", "%3D");
        }
    }
}

Decode the encoded parameter in stored procedure:

Sample code:

CREATE PROCEDURE [dbo].[InsertToDo]
   @order int,
   @title nvarchar(200),
   @url nvarchar(200),
   @completed bit
AS
BEGIN
   SET NOCOUNT ON;

   DECLARE @decodedUrl nvarchar(200)
   SET @decodedUrl = REPLACE(@title, '%3D', '=')

END

Refer GitHub issue on the same.