Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft.Data.SqlClient.SqlException(0x80131904):靠近“,”的语法不正确_C#_Sql Server_Api_Asp.net Core_Stored Procedures - Fatal编程技术网

C# Microsoft.Data.SqlClient.SqlException(0x80131904):靠近“,”的语法不正确

C# Microsoft.Data.SqlClient.SqlException(0x80131904):靠近“,”的语法不正确,c#,sql-server,api,asp.net-core,stored-procedures,C#,Sql Server,Api,Asp.net Core,Stored Procedures,我相信这可能是语法错误,但我找不到它 这是全部错误: Microsoft.Data.SqlClient.SqlException 0x80131904:语法不正确 在“,”附近。在 Microsoft.Data.SqlClient.SqlCommand.c.b_uu164_0Task1 结果 System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke 在System.Threading.Tasks.Task.c

我相信这可能是语法错误,但我找不到它

这是全部错误:

Microsoft.Data.SqlClient.SqlException 0x80131904:语法不正确 在“,”附近。在 Microsoft.Data.SqlClient.SqlCommand.c.b_uu164_0Task1 结果 System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke 在System.Threading.Tasks.Task.c.b__274_0对象对象在 System.Threading.ExecutionContext.RunInternalExecutionContext executionContext、ContextCallback回调、对象状态 -来自引发异常的上一个位置的堆栈结束跟踪-在 System.Threading.Tasks.Task.ExecuteWithThreadLocalTask& currentTaskSlot,线程池线程 -来自引发异常的上一个位置的堆栈结束跟踪-在 Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsyncRelationalCommandParameterObject parameterObject,CancellationToken CancellationToken位于 Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsyncRelationalCommandParameterObject parameterObject,CancellationToken CancellationToken位于 Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsyncRelationalCommandParameterObject parameterObject,CancellationToken CancellationToken位于 Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsyncDbContext _,布尔结果,CancellationToken CancellationToken位于Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult]TState 状态,Func4操作,Func4验证成功,CancellationToken 取消令牌在 Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync 在 Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListSync[TSource]IQueryable1 源,CancellationToken CancellationToken位于 Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListSync[TSource]IQueryable1 源,CancellationToken CancellationToken位于 FincredixAppBigBrotherWebApi.Application.Sucursales.Queries.GetAllSucursales.GetAllSucursalesHandler.HandleGetAllSucursalesQuery 请求,取消令牌取消令牌位于 C:\Users\alozano\source\repos\FincredixAppBigBrotherWebApi\FincredixAppBigBrotherWebApi.Application\Sucursales\Queries\GetAllSucursales\GetAllSucursalesHandler.cs:line 28时 MediatR.Pipeline.RequestPreProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPostProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPreProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPostProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPreProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPostProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 MediatR.Pipeline.RequestPreProcessorBehavior2.HandleTRequest 请求,CancellationToken CancellationToken,RequestHandlerDelegate1 下一个 FincredixAppBigBrotherWebApi.WebApi.Controllers.SucursalController.GetAllInt32 claSucursal,Int32 claSucursalPadre,Int32 bajaLogica,字符串 描述 C:\Users\alozano\source\repos\fincredixappbigbootherwebapi\fincredixappbigbootherwebapi.WebApi\Controllers\SucursalController.cs:line 19在lambda_方法闭包处,对象在 Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult 在 Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.ExecuteActionResultTypeMapper 映射器,ObjectMethodExecutor,对象控制器,对象[] 争论 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g|u等待| 12_0ControllerActionInvoker 调用程序,ValueTask`1 actionResultValueTask位于 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g|u waiting | 10_0ControllerActionInvoker 调用程序、任务lastTask、状态next、作用域、对象状态、布尔值 完成于 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.RethrowActionExecutedContextSealed 上下文 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.NextState& 接下来,范围和范围、对象和状态、布尔值和在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g|u waiting | 13_0ControllerActionInvoker 调用程序、任务lastTask、状态next、作用域、对象状态、布尔值 完成 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g|u waiting|19_0ResourceInvoker 调用程序、任务lastTask、状态next、作用域、对象状态、布尔值 完成于 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g|u waiting|17_0ResourceInvoker 调用程序、任务、IDisposable作用域 Microsoft.AspNetCore.Routing.EndpointMiddleware.g|u waitRequestTask | 6_0Endpoint 端点、任务请求任务、ILogger记录器位于 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.InvokeHttpContext 上下文 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.InvokeHttpContext 上下文客户端连接ID:25b62d0a-cacd-4e27-aa37-90c4cd002382错误 编号:102,州:1,类别:15

标题 ======缓存控制:无缓存连接:保持活动接受:/Accept编码:gzip,deflate,br主机:localhost:5001用户代理: 邮递员运行时/7.22.0邮递员令牌: bdd4ae12-be9d-4d55-9753-36f00ca7029c

这是我怀疑的代码行

在 FincredixAppBigBrotherWebApi.Application.Sucursales.Queries.GetAllSucursales.GetAllSucursalesHandler.HandleGetAllSucursalesQuery 请求,取消令牌取消令牌位于 C:\Users\alozano\source\repos\FincredixAppBigBrotherWebApi\FincredixAppBigBrotherWebApi.Application\Sucursales\Queries\GetAllSucursales\GetAllSucursalesHandler.cs: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;
}
我已经看到许多与此非常相似的问题,但不正确的语法是“?”或“from”或“/”等。我的是“,”

不应该是:

 $@"{SpConstants.SpAppFcxSucursalSel}
                    @pnClaSucursal = '{request.ClaSucursal}',
                    @psDescripcion = '{request.Descripcion}',
                    @pnClaSucursalPadre = '{request.ClaSucursalPadre}',
                    @pnIncBajaLogica = '{request.BajaLogica}'")

不要使用字符串连接构建SQL。使用参数化查询。如果任何变量包含SQL特殊字符,则可能会出现此错误。遵循Daniel的建议。我知道如何进行参数化查询,但在当前的情况下,我不需要返回某个ViewModel的列表,加上它必须是异步的。运行该查询时,生成的SQL查询是什么?冒着听起来有点讽刺的风险,我认为我们应该看看a附近,因为语法错误存储过程在SSMS中执行时运行良好,所以我知道问题不在于sp。是的,我听到了,这不是讽刺,一定有逗号缺失或多余。我只是不知道在哪里。我会在早上尝试第一件事,但我有我的怀疑,因为当我调试并在那一行设置断点时,当我将鼠标悬停在4个参数上时,它们具有来自请求的预期值。就是这样!将请求参数放在单引号中使其工作起来很有魅力,非常感谢。