Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Record locking in ASP

Posted on 2003-02-24
6
Medium Priority
?
226 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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/…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

575 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