如何清除sql命令的参数缓存?

发布于 2024-08-21 15:27:12 字数 430 浏览 2 评论 0原文

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

        Database dBase = DatabaseFactory.CreateDatabase();

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

        return dBase.ExecuteDataSet(dCommand);

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

I'm using Enterprise Library's DAAB. I have code like this:

        Database dBase = DatabaseFactory.CreateDatabase();

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

        return dBase.ExecuteDataSet(dCommand);

How can I clear the parameter cache? It seems that when you have two SPs with similar names, e.g. "GetUser" and "GetUser_Data" it saves the first ones parameters which results in a the "amount of parameters does not match the value of the stored procedure" error when you call the second one after it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-08-28 15:27:12

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

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

I can't tell from your code but it sounds like you're reusing the DbCommand object, and it's attaching more params the second time around. Try creating a new DbCommand instance each query.

Alternatively, can you just do a DbCommand.DbParameterCollection.Clear() ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文