?
Solved

Record locking in ASP

Posted on 2003-02-24
6
Medium Priority
?
225 Views
Last Modified: 2012-05-04
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
%>


0
Comment
Question by:diamil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
apollois earned 900 total points
ID: 8012385
Convert to stored procedure.

More secure, much better performance, easier to test/debug.

Best Regards,
apollois
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8013284
Ya I completly agree. Allot of people use dynamic sql to generate simply select, insert, or update queries.  But your dynamically generating a whole procedure...would be much better to write the stored procedure and pass the parameters in.

not looking for points just trying to reinforce appollois suggestion.
0
 
LVL 10

Expert Comment

by:apollois
ID: 8018957
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 (http://www.experts-exchange.com/Community_Support/).  Include a link to this question, and the new grade.

Best Regards,
apollois
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:diamil
ID: 8022064
I gave B, because I was waiting for something that will help me use a transaction, sorry for the B.

Thanks
0
 
LVL 10

Expert Comment

by:apollois
ID: 8022149
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
0
 

Author Comment

by:diamil
ID: 8083585
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
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question