You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EF 6.4.4调用SQL Server存储过程间歇性报错:找不到存储过程' '

间歇性EF6调用存储过程报错:找不到存储过程' '

问题现象

我们的C#应用使用Entity Framework 6.4.4访问SQL Server实例,间歇性出现存储过程调用失败,抛出异常:

EntityCommandExecutionException: Could not find stored procedure ' '

该问题在客户生产服务器上过去数月出现约十余次,开发和测试环境多次尝试复现均未成功。

已做排查

  • 检查SQL Server日志和Windows事件日志,未发现报错时有异常高资源占用,排除资源耗尽类问题
  • 查阅官方文档未找到相关记录,仅在EF6的GitHub仓库中发现一个与IDbInterceptor相关的Bug报告,但我们仅在单个查询中使用拦截器,报错出现在未使用拦截器的查询上
  • 所有存储过程调用代码均由Visual Studio从EDMX(数据库优先模型)自动生成,调用模式统一,正常情况下运行稳定

代码示例

自动生成的实体结果类型

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace DAL.Entities
{
    using System;
    
    public partial class GetAllConditionCodes_Result
    {
        public int ID { get; set; }
        public string ConditionCodeNumber { get; set; }
        public string Description { get; set; }
        public bool IsDeleted { get; set; }
    }
}

EF自动生成的存储过程调用方法

public virtual ObjectResult<GetAllConditionCodes_Result> GetAllConditionCodes(Nullable<System.DateTime> lastUpdateTime)
{
    var lastUpdateTimeParameter = lastUpdateTime.HasValue ?
            new ObjectParameter("LastUpdateTime", lastUpdateTime) :
            new ObjectParameter("LastUpdateTime", typeof(System.DateTime));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetAllConditionCodes_Result>("GetAllConditionCodes", lastUpdateTimeParameter);
}

数据访问层调用代码

public List<ConditionCode> GetAllConditionCodesFromDatabase(DateTime? lastUpdateTime = null)
{
    var conditionCodes = new List<ConditionCode>();

    using (var context = CreateObjectContext())
    {
        var result = context.GetAllConditionCodes(lastUpdateTime).ToList();
        conditionCodes = Mapper.Map<List<Entities.GetAllConditionCodes_Result>, List<ConditionCode>>(result);
    }

    return conditionCodes;
}

异常详情

  • 外层异常:System.Data.Entity.Core.EntityCommandExecutionException

    An error occurred while executing the command definition. See the inner exception for details.

  • 内层异常:System.Data.SqlClient.SqlException

    Could not find stored procedure ' '

注意:异常中报告的存储过程名为单个空格字符,而非实际要调用的GetAllConditionCodes。

希望能得到解决该间歇性问题的思路或方案。


内容的提问来源于stack exchange,提问作者Suncat2000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 04:05:33