如何清除sql命令的参数缓存?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法从您的代码中看出,但听起来您正在重用 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() ?