java.sql.BatchUpdateException: Transaction (Process ID 58) was
deadlocked on lock resources with another process and has been chosen
as the deadlock victim. Rerun the transaction.
I have two java application one reading data from sybase and writing to an sql server 2008 and another reading data from sql server 2008 table and writing it to other table. Now the two application works fine. But I have many people accessing data from mssql table where the second application updates data every 30 sec. So I get the above exception. I saw similar thread here in stackoverflow but
Deadlock troubleshooting in Sql Server 2008
I have problem with the solution presented here with
row versioning
can I user rowversioning to avoid dead locks in my situation and How could I use it?
Edit
String selectAllQuery = "Select new_site_id from GIS.MAP.ro";
String selectQuery = "Select siteId from GIS.MAP.status where AlarmCode in ('1','2','3') and localNodeAlias like 'FLM%'";
String updateQuery = "update GIS.MAP.ro set active_site_status = ? where new_site_id = ?";
String updateAllQuery = "update GIS.MAP.ro set active_site_status = site_status where new_site_id = ?";
So, I select from GIS.MAP.status table and update update GIS.MAP.ro table. Actually GIS.MAP.status table is also update every 30 sec(the whole table is deleted and inserted but the two task
- inserting into GIS.MAP.status goes first and transaction is
committed - updating GIS.MAP.ro table goes second and transaction
is committed - Finally, The data from GIS.MAP.ro is accessed by many user by third party application.
Actually the deadlock occours at this instance.
In most cases deadlocks indicate that there’s something wrong with your implementation – there’s a problem with query order, locking order or join order. I’d suggest collecting and analyzing your deadlocks (MSDN: Analyzing Deadlocks with SQL Server Profiler) so you may find exact places in your code where deadlocks occur and fix them.