Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 4th, 2004, 03:06 PM
PSzalapski PSzalapski is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 PSzalapski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Locking problem LCK_M_IX on update

Using Microsoft SQL Server 2000 over ODBC, I have a script wherein I am running into a locking problem. Here's what I'm doing, in pseudocode:
Code:
query = "SELECT keyCol1, col2 FROM t1";
   dbConnection1.prepare(query);
   dbConnection1.execute();
   for each row in (dbConnection1.result()) {
            	...
            	query = "UPDATE t1 SET col2='xx' WHERE keyCol1=" + row.keyCol1;
            	dbConnection2.do(query);
            }
            


My problem is that there is some kind of lock placed by the first query which is prohibiting the second query! The query hangs without any error message. After investigating, the UPDATE query is blocked in trying to acquire a intent-exclusive lock, because a shared lock has been placed by Connection1. How do I select without placing a shared lock? Why can't I modify the record I just read from?

I am set to
READ COMMITTED transaction isolation level, which shouldn't matter...

I have another database on the same server which, when I do the same queries, does NOT place a shared lock when executing the SELECT statements. Are there any database-level settings that I can check to investigate this?
P-Sz

Last edited by PSzalapski : May 4th, 2004 at 04:22 PM. Reason: incomplete post

Reply With Quote
  #2  
Old May 4th, 2004, 10:08 PM
Onslaught Onslaught is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 34 Onslaught User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 6
Move to SQL Server forum & updated title.

Reply With Quote
  #3  
Old May 8th, 2004, 02:54 PM
Chizl Chizl is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 14 Chizl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It's highly suggested from Microsoft to use OLEDB instead of ODBC direct, OLEDB is just faster and more efficient.

READ COMMITTED is by default from understanding, which causes a LOCK to happen, but why would you want that, when SQL does this automatically? If your locking it, then you need to unlock it right.

BTW the language it looks like your using is C++, why are you not using ADO? I don't recognize the properties of your connection object. Is that a database control or something? If so, I highly suggest removing that, because that will only slow everything down and you very limited to what you can do.

Quick and dirty as VB example because the code is shorter.. Go to http://www.chizl.com/dev/c++/ for a c++ example on ADO, and using getrows vs looping through the recordset, which is also every slow.

sqlStatement = "Select..";
set objRS = objConn.execute(sqlStatement);
If not objRS.EOF then vData = objRS.GetRows
objRS.Close
set objRS = nothing

for i = 0 to ubound(vData,2)
sqlStatement = "Update";
objConn.execute(sqlStatement);
next

ALSO.. Your SQL Statement, selecting from the same table your updating too..

SELECT keyCol1, col2 FROM t1
UPDATE t1 SET col2='xx' WHERE keyCol1=" + row.keyCol1

All you have to do is loose the where clause on your update and delete your select statement to do exactly the same thing with No Looping at all.

Final result:
UPDATE t1 SET col2='xx'

Last edited by Chizl : May 8th, 2004 at 02:56 PM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Sql locking tables on a select cause


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway