【问题标题】:How to clear the parameter cache of a sql command?如何清除sql命令的参数缓存?
【发布时间】:2011-01-15 13:00:35
【问题描述】:

我正在使用 Enterprise Library 的 DAAB。我有这样的代码:

        Database dBase = DatabaseFactory.CreateDatabase();

        DbCommand dCommand = dBase.GetStoredProcCommand(StoredProcedureName, Parameters);
        dCommand.CommandTimeout = CommandTimeout;

        return dBase.ExecuteDataSet(dCommand);

如何清除参数缓存?似乎当您有两个名称相似的 SP 时,例如“GetUser”和“GetUser_Data”它保存了第一个参数,当您在它之后调用第二个参数时,会导致“参数数量与存储过程的值不匹配”错误。

【问题讨论】:

    标签: c# caching enterprise-library parameters daab


    【解决方案1】:

    我无法从您的代码中看出,但听起来您正在重用 DbCommand 对象,并且它第二次附加了更多参数。尝试为每个查询创建一个新的 DbCommand 实例。

    或者,您可以只执行 DbCommand.DbParameterCollection.Clear() 吗?

    【讨论】:

    • 我试过 DbCommand dCommand = new DbCommand,但是它不允许我这样做,我得到编译错误。您看到的代码是我在数据访问层中调用的方法,它传入了 SP 名称和参数值。
    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 2014-05-28
    • 2016-11-10
    • 2015-09-27
    • 2018-05-27
    • 1970-01-01
    • 2012-03-30
    相关资源
    最近更新 更多