Advertisement

03.31.2008 at 06:55PM PDT, ID: 23284577
[x]
Attachment Details

Windows service on multiple application servers causes data collisions

Asked by LloydMc in .Net Editors & IDEs, Microsoft Visual C#.Net, .NET Framework 2.x

Tags: , , ,

We're attempting to run a .Net 2.0 C# windows service concurrently on two application servers for scalability reasons, but am running into data concurency issues.  The services poll the request table for new requests every 30 secs and I'm wrestling with finding a good way to prevent them from grabbing the same request and duplicate processing. Each windows service batch process requests entered through a web application and stored in a Sql Server 2000 table.  The requests have statuses representing their process stage (1 = New, 2 = In-Process, 3 = Complete, 4 = Error).  

I've tried the following processing server ownership approach which hasn't worked: adding a column to the request table to store the app server machine name and setting it and the request status within an update stored procedure.  The sproc contains a Top 1 predicate and new request status criteria select inside a loop whose iterator is set by a parameter so I can return multiple rows per pass. The rows are updated then the effected request id(s) are returned to the service in a separate select. The first method called in the .Net windows service executes the aforementioned stored proc,  gathers the returned request ids into a collection which I then iterate and create new request entities from using per entity selects.  

The logic then attempts to prevent concurrency by using an update stored proc with its row locking along with logic in the .Net windows service main processing method to compare the executing environment machine name against the one in the request entity attribute and only proceed if they match.

Is there a better approach to take?  Boy I hope so!Start Free Trial
 
Loading Advertisement...
 
[+][-]03.31.2008 at 09:02PM PDT, ID: 21251184

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .Net Editors & IDEs, Microsoft Visual C#.Net, .NET Framework 2.x
Tags: Microsoft, Visual C#, 2005, Dell
Sign Up Now!
Solution Provided By: anyoneis
Participating Experts: 2
Solution Grade: B
 
 
[+][-]04.01.2008 at 08:51AM PDT, ID: 21255154

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628