Parallel Execution of SQL in ADO.Net on C# - SQL Parameter is already contained

  • Hi there

    Im not sure if this should be asked on a C# forum, but im taking a shot here. We have a C# Application which using ADO.Net , executes SQL Stored procedures.

    In  fact the application calles SQL stored procedures in Parallel.

    The issue we have is trying to achieve Parallel execution in c#

    When we start up the application,  we get the following error message

    System.ArgumentException: 'The SqlParameter is already contained by another SqlParameterCollection.'

    (Please see attached screenshot)

    The thing is from the SQL profile trace , i can see that the actual stored procedure spSetChannelReading has completed execution...

    We put a lock in c# but this leads to single threading which is slow and not desirable.

    So my question is that how do you do  parrallel execution of stored procedures in a C# application without encountering this error?

     

     

  • That looks more like a C# error than a SQL issue.

    A brief Google search suggested this.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • This was removed by the editor as SPAM

  • Thanks Phil. Yeah I saw that article and tried cmd.Parameters.Clear  but to no avail.

     

  • I think the problem is that you're trying to use the same parameter for two procedures that are running concurrently. You'll need to have a separate set of parameters for each procedure; you can set multiple parameters to the same value, but you can't share the parameters themselves.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply