diamil
asked on
Record locking in ASP
How can I fix this is asp
Microsoft OLE DB Provider for SQL Server error '80004005'
Transaction (Process ID 74) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
/mypage.asp, line 87
This is the code
<%
sqlstr2 = "IF NOT EXISTS "&_
"(SELECT site_id FROM Mcounter WHERE site_id = " & RS("site_id") & " AND type_id = " & RS("type_id") & " AND year_click = " & varYear & ") "&_
"BEGIN " &_
"INSERT INTO mCounter (company_id, site_id, type_id, year_click, " & varMonth & ") "&_
"VALUES "&_
"(" & RS("company_id") & ", " & RS("site_id") & ", " & RS("type_id") & ", " & varYear & ", 1) "&_
"END " &_
"ELSE " &_
"BEGIN " &_
"UPDATE Mcounter SET " & varMonth & " = " & varMonth & " + 1 WHERE site_id = " & RS("site_id") & " AND type_id = " & RS("type_id") & " AND year_click = " & varYear & " "&_
"END"
Myconn.Execute(mysql) 'this code is generating the eror
%>
Microsoft OLE DB Provider for SQL Server error '80004005'
Transaction (Process ID 74) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
/mypage.asp, line 87
This is the code
<%
sqlstr2 = "IF NOT EXISTS "&_
"(SELECT site_id FROM Mcounter WHERE site_id = " & RS("site_id") & " AND type_id = " & RS("type_id") & " AND year_click = " & varYear & ") "&_
"BEGIN " &_
"INSERT INTO mCounter (company_id, site_id, type_id, year_click, " & varMonth & ") "&_
"VALUES "&_
"(" & RS("company_id") & ", " & RS("site_id") & ", " & RS("type_id") & ", " & varYear & ", 1) "&_
"END " &_
"ELSE " &_
"BEGIN " &_
"UPDATE Mcounter SET " & varMonth & " = " & varMonth & " + 1 WHERE site_id = " & RS("site_id") & " AND type_id = " & RS("type_id") & " AND year_click = " & varYear & " "&_
"END"
Myconn.Execute(mysql) 'this code is generating the eror
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
diamil,
Thanks for selecting my comment as the answer. But why the grade of "B"?
The recommendation I gave you, confirmed by chisholmd, is probably the best thing you can do to solve your problem. I realize that it may not have been the answer you were looking for, but none-the-less, it is a sound answer.
If you have any related questions, I will be glad to help you.
Please see Tip #11 - Grade quickly and fairly
http://cd-eepages.fateback.com/asking.html
If you wish to change the grade, you can post a zero-point question with Community Support (https://www.experts-exchange.com/Community_Support/). Include a link to this question, and the new grade.
Best Regards,
apollois
Thanks for selecting my comment as the answer. But why the grade of "B"?
The recommendation I gave you, confirmed by chisholmd, is probably the best thing you can do to solve your problem. I realize that it may not have been the answer you were looking for, but none-the-less, it is a sound answer.
If you have any related questions, I will be glad to help you.
Please see Tip #11 - Grade quickly and fairly
http://cd-eepages.fateback.com/asking.html
If you wish to change the grade, you can post a zero-point question with Community Support (https://www.experts-exchange.com/Community_Support/). Include a link to this question, and the new grade.
Best Regards,
apollois
ASKER
I gave B, because I was waiting for something that will help me use a transaction, sorry for the B.
Thanks
Thanks
diamil,
Well, if I didn't answer your question, then you should not have selected my comment as answer.
It would have been better if you would have posted your above comment before selecting the comment.
So, I'd recommend that you ask CS to reopen the question so we can give you the proper help.
Having said that, can you convert your SQL to a stored procedure?
Best Regards,
apollois
Well, if I didn't answer your question, then you should not have selected my comment as answer.
It would have been better if you would have posted your above comment before selecting the comment.
So, I'd recommend that you ask CS to reopen the question so we can give you the proper help.
Having said that, can you convert your SQL to a stored procedure?
Best Regards,
apollois
ASKER
I did not implemente the solution using a stored procedure (I do recognize that using a stored procedure is better and more reliable). If you look closely at the query I posted the logic was wrong. Since we have more updates than adding a new record, it was better to create two separate queries
If user exist then
update query
end if
if user does not exist then
add a new record query
end if
this logic was able to solve my problem.
Thanks
If user exist then
update query
end if
if user does not exist then
add a new record query
end if
this logic was able to solve my problem.
Thanks
not looking for points just trying to reinforce appollois suggestion.