October 10, 2008 at 9:43 am
We have a multi-threaded C# application that uses the SqlDataAdapter to get data returned from stored procedures.
We have unique classes for each SP so the reference to this.sqlCommand in the code below is local to the object created for a specific SP.
The following code exists in each one of these classes (say FetchData_SP_1 and FetchData_SP_2) so the dataSet should be the data returned from the SP that object pertains to.
void Execute()
{
....
SqlDataAdapter adapter = new SqlDataAdapter(this.sqlCommand);
adapter.Fill(this.dataSet);
....
}
We will then be calling FetchData_SP_1.Execute() and FetchData_SP_2.Execute() in different threads.
The problem is that occasionally the data returned by the Fill method is for a SP other than the one being called in this.sqlCommand.
I have added breakpoints to verify that this.sqlCommand is for one SP and the dataSet returned is data from a different SP.
Has anyone else seen issues using SqlDataAdapter.Fill in multiple threads?
Thanks
October 10, 2008 at 4:45 pm
If you are having this kind of issue, then you have something that is not thread safe in your implementation, which we can't see in the little bit of code that you have provided. Start by looking for static objects that could be changed by another thread. Then try implementing a locker object on your SqlCommand until the Fill is complete.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
January 4, 2009 at 5:40 am
Paul,
Even I exactly have a similar issue....
Please let me know if you have found a solution..
Thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply