Microsoft.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ','

-1

I believe this may be a syntax error, but I cannot find it.

This is the full error:

Microsoft.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ','. at Microsoft.Data.SqlClient.SqlCommand.<>c.b__164_0(Task1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location where exception was thrown --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location where exception was thrown --- at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at FincredixAppBigBrotherWebApi.Application.Sucursales.Queries.GetAllSucursales.GetAllSucursalesHandler.Handle(GetAllSucursalesQuery request, CancellationToken cancellationToken) in C:\Users\alozano\source\repos\FincredixAppBigBrotherWebApi\FincredixAppBigBrotherWebApi.Application\Sucursales\Queries\GetAllSucursales\GetAllSucursalesHandler.cs:line 28 at MediatR.Pipeline.RequestPreProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPostProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPreProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPostProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPreProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPostProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at MediatR.Pipeline.RequestPreProcessorBehavior2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate1 next) at FincredixAppBigBrotherWebApi.WebApi.Controllers.SucursalController.GetAll(Int32 claSucursal, Int32 claSucursalPadre, Int32 bajaLogica, String descripcion) in C:\Users\alozano\source\repos\FincredixAppBigBrotherWebApi\FincredixAppBigBrotherWebApi.WebApi\Controllers\SucursalController.cs:line 19 at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) ClientConnectionId:25b62d0a-cacd-4e27-aa37-90c4cd002382 Error Number:102,State:1,Class:15

HEADERS ======= Cache-Control: no-cache Connection: keep-alive Accept: / Accept-Encoding: gzip, deflate, br Host: localhost:5001 User-Agent: PostmanRuntime/7.22.0 Postman-Token: bdd4ae12-be9d-4d55-9753-36f00ca7029c

This is the line of code I suspect

at FincredixAppBigBrotherWebApi.Application.Sucursales.Queries.GetAllSucursales.GetAllSucursalesHandler.Handle(GetAllSucursalesQuery request, CancellationToken cancellationToken) in C:\Users\alozano\source\repos\FincredixAppBigBrotherWebApi\FincredixAppBigBrotherWebApi.Application\Sucursales\Queries\GetAllSucursales\GetAllSucursalesHandler.cs:line 28

And this is the line 28:

public async Task<List<SucursalViewModel>> Handle(GetAllSucursalesQuery request, CancellationToken cancellationToken)
{
    var response = this._mapper.Map<List<SucursalViewModel>>(await this._fincredixAppDbContext.SpAppFcxSucursalSel.FromSqlRaw(
                    $@"{SpConstants.SpAppFcxSucursalSel}
                    @pnClaSucursal = { request.ClaSucursal },
                    @psDescripcion = { request.Descripcion },
                    @pnClaSucursalPadre = { request.ClaSucursalPadre },
                    @pnIncBajaLogica = { request.BajaLogica }")
                    .AsNoTracking().ToListAsync(cancellationToken));
    return response;
}

I have already seen many questions very similar to this one but the Incorrect syntaxes are '?' or ')' or 'from' or '/' etc. Mine is ','

c#
sql-server
api
asp.net-core
stored-procedures
asked on Stack Overflow Jan 28, 2020 by Arturo Lozano • edited Jan 29, 2020 by Dale K

1 Answer

1

Shouldn't it be:

 $@"{SpConstants.SpAppFcxSucursalSel}
                    @pnClaSucursal = '{request.ClaSucursal}',
                    @psDescripcion = '{request.Descripcion}',
                    @pnClaSucursalPadre = '{request.ClaSucursalPadre}',
                    @pnIncBajaLogica = '{request.BajaLogica}'")
answered on Stack Overflow Jan 29, 2020 by JBrooks

User contributions licensed under CC BY-SA 3.0