views:

199

answers:

1

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.

+1  A: 

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

Rob Elliott
I've tried DbCommand dCommand = new DbCommand, however it doesn't allow me to do that, I get compile errors. The code you see is a method I call in my data access layer that passes in the SP name and Parameter values.
Jinxed