473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Locking Problem: SQL Server

Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #1
5 5461
Ray
Ritesh,

ReadPast only skips row level locks. sp_who2 will not show you the
granularity of the lock for that use sp_lock. You are correct that only
NoLock will read without blocking but it comes with a price of potentially
reading dirty pages. In SQL 2005 a new isolation level will be added called
SnapShot that will give you what you are looking for.

Ray

"Ritesh" <ri************ **@yahoo.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #2
Thanks Ray,

Can there be any solutions to SELECT statements not blocking Insert statements?

Regards,
Ritesh

"Ray" <so*****@nowher e.com> wrote in message news:<Ns******* ************@ne wssvr33.news.pr odigy.com>...
Ritesh,

ReadPast only skips row level locks. sp_who2 will not show you the
granularity of the lock for that use sp_lock. You are correct that only
NoLock will read without blocking but it comes with a price of potentially
reading dirty pages. In SQL 2005 a new isolation level will be added called
SnapShot that will give you what you are looking for.

Ray

"Ritesh" <ri************ **@yahoo.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #3
Pehaps you are asking the wrong question. I would be asking why the select
queries are running long enough to block the update queries. If applications
are written correctly then select queries should run quickly enough that
updates are not blocked for long.

Specifically in 2000 you can only use nolock or set the the isoation level
to dirty read for the query (does the same), you cannot guarantee to get
clean data if you do this. It will depend on what the users need if this is
acceptable.

Shared locks will block update locks this is correct and expected. Also SQL
2000 will only allow exclusive locks to be blocked 4 times (from memory) by
shared locks before it lets the exclusive locks through (this gives further
weight to the question as to why the select queries are taking so long)

Help this helps
Julian
"Ritesh" <ri************ **@yahoo.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #4
Ritesh,

Normally insert statement will not block on select statement. But there are
exceptions. For example, when the lock granularity of the insert is the
page level, then it can block on page lock held by select statement. If
this is the case, the force insert to take row lock using ROWLOCK will
remove the blocking. Or if the select statement is run under read repeatable
or serializable isolation level, then the select takes some kind of key
range lock which prevents insert into the range locked. If this is the
case, changebthe select isolation level to read committed will remove
blocking. Finally you may need to do some homework to find out which lock
the insert is blocked on by the select, which you can query sysprocesses and
syslockinfo to find out.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ritesh" <ri************ **@yahoo.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #5
Hi,

You are correct but the problem is my select queries are blocking
insert statements and select statements are running in default
isolation level. The problem is, I inheriated this design, which is
OLTP in nature but the DB is also queried extensively for newly
inserted records.

Can there be any way to completely avoid just inserting records
(showing in the query. It is acceptable for business logic, say
READPAST will do.) and also the query (same select query) not blocking
newly inserting records but not reading any dirty data? or I am asking
to much from SQL Server? :)

What do you say?

Thanks & Regards,
Ritesh Khanna

"Gang He [MSFT]" <ga************ **@microsoft.co m> wrote in message news:<42******* *@news.microsof t.com>...
Ritesh,

Normally insert statement will not block on select statement. But there are
exceptions. For example, when the lock granularity of the insert is the
page level, then it can block on page lock held by select statement. If
this is the case, the force insert to take row lock using ROWLOCK will
remove the blocking. Or if the select statement is run under read repeatable
or serializable isolation level, then the select takes some kind of key
range lock which prevents insert into the range locked. If this is the
case, changebthe select isolation level to read committed will remove
blocking. Finally you may need to do some homework to find out which lock
the insert is blocked on by the select, which you can query sysprocesses and
syslockinfo to find out.

--
Gang He
Software Design Engineer
Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ritesh" <ri************ **@yahoo.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Hi All,

According to my observation using SP_WHO2 in my database, some INSERT
statements are getting blocked by SELECT statements. Though the
blocking
SELECT statement is having ReadPast hint, i think, it will only read
past
locked resources but will not guarantee the select statement itself not
blocking other statements(in my case Insert). According to my knowledge

and
information, select statements take shared locks but why then these
statements are blocking insert statements?

Can there be any other solution other than using NoLock hint as this
hint
make sure no shared locks are issued but it can read uncommited data.

Need help urgently.

Thanks
Ritesh

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5124
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often the users (when they bother to tell me) find that the application locks up and they are unable to work. No errors are produced (error trapping in the app is good). They 'shout round' to each other and get someone to exit the data entry screen....
9
5068
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to access them and automatically they can not continue their works. I have tried using the following code, but it does not work. I always got the error :
2
6875
by: Randall Sell | last post by:
Hello all, Somewhere on these newsgroups I recall reading that SQL Server 6 and prior (when they were married with Sybase) used page locking and not row level locking. Hence you could be locking a lot more records then what you think when doing an UPDATE or INSERT SQL. Now I notice that SQL Server 7 and 2000 claim to use row level locking. (As you can see, I have been out of the SQL arena for some time). So what I'd like to know if...
16
8932
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
3
2769
by: Wolfgang Bachmann | last post by:
We migrated a database from Version 5.1 to 8.1 and are experiencing massive locking problems. We migrated in the following steps: 0) Server 5.2, Clients 5.2: everithing was fine 1) Server 5.2, Clients 6.1: everything still fine 2) Server 8.1, Clients 6.1: here the problem occurs 3) server 8.1, Clients 8.1: not yet done. Steps 1 & 2 were nessecary because there are to many clients spread over to much area to migrate all at once from...
2
2146
by: Shaun | last post by:
Ok here is the situation… Have an access 20002 application that I'm converting to have a SQL Server backend (2000), the application has been in use with an access backend for years, no real problem, just getting large so needed to migrate to SQL. I've converted the tables in SQL tables (I've used SQL quite a lot) and link the tables when the login screen for the application pops up using the following code Dim CurrTableTDF As TableDef
15
6202
by: z. f. | last post by:
Hi, i have an ASP.NET project that is using a (Class Library Project) VB.NET DLL. for some reason after running some pages on the web server, and trying to compile the Class Library DLL, it can't compile because the DLL is in use (and the PDB too), and the w3wp.exe process is the process locking the DLL (as viewed with Sysinternals - Process Explorer). this is a huge problem. i need to do IIS reset in order to free the DLL! 1. why is...
7
2865
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets send the messagetype via async NetworkStream ns = client.GetStream(); //assume client globally accessible
3
1875
by: David C. Barber | last post by:
How do you lock a record in SQL Server from ASP 2? I need to read the record, allow the user to edit it, and then have them click Save and rewrite it. Obviously I don't want anyone else getting into this record while the user has it up. I don't see how to have SQL Server lock this record for me since the connection drops the moment the page is written, and would prefer to avoid the kludge of adding and handling reservation fields to each...
9
2604
by: zmickle | last post by:
Experts and books all say that you can share an Access back end on a shared drive with the front end running on each host computer. I have a simple database that tracks student data and it is shared between 4 staff memebers. Each staff computer has a copy of the front-end (linked tables, forms, and queries). They basically only use one form. The form works like this
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.