Jinxed
Jinxed

Reputation: 1

How to clear the parameter cache of a sql command?

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.

Upvotes: 0

Views: 3992

Answers (1)

Rob Elliott
Rob Elliott

Reputation: 2008

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() ?

Upvotes: 2

Related Questions