473,503 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong result Set when using NoLock

bmm
I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint
"NoLock" on all selects.

One of my clients (OleDbConnection from C#) doesn't get the same Result Set
as the others. The result Set should have 31 rows but this client only gets
5!

When I remove all the "NoLocks" everything works fine. How can that be?
Oct 22 '07 #1
5 2917


"bmm" <bm*************@comlog.dkwrote in message
news:47***********************@dtext01.news.tele.d k...
>I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint
"NoLock" on all selects.

One of my clients (OleDbConnection from C#) doesn't get the same Result
Set as the others. The result Set should have 31 rows but this client only
gets 5!
Since you said "others" I'm a bit confused. If you had said ONE other got
31 and everyone else was getting 5 I'd say that makes perfect sense due to
how transactions work and how (nolock) works. (i.e. my guess would be you
have an open transaction someplace).

>
When I remove all the "NoLocks" everything works fine. How can that be?
In this case, off the top of my head, I can't quite figure out the scenario
that would give this behavior).

>
--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
Oct 22 '07 #2
bmm (bm*************@comlog.dk) writes:
I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint
"NoLock" on all selects.

One of my clients (OleDbConnection from C#) doesn't get the same Result
Set as the others. The result Set should have 31 rows but this client
only gets 5!

When I remove all the "NoLocks" everything works fine. How can that be?
Maybe you could clarify a few things.

When you say "client" is that "client" as in "customer" or as in "client
computer"? Does the client that only gets five rows run the same application
as those that get 31? If they run different applications, doethe other
application use a different API?

Is this behaviour constistent? That is, does it happen even if there is
no activity on the system, so that there are no locked rows?

Would it be possible for you to post the code of the procedure?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 22 '07 #3
On Oct 22, 3:52 am, "bmm" <bmmsletdette...@comlog.dkwrote:
I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint
"NoLock" on all selects.

One of my clients (OleDbConnection from C#) doesn't get the same Result Set
as the others. The result Set should have 31 rows but this client only gets
5!

When I remove all the "NoLocks" everything works fine. How can that be?
Hi there,
I am posting few lines from SQL Sever magazine article written by
Itzik Ben-Gan:

"
With the NOLOCK hint (or setting the isolation level of the session
to READ UNCOMMITTED) you tell SQL Server that you don't
expect consistency, so there are no guarantees.
Bear in mind though that "inconsistent data" does not only mean that
you might see uncommitted changes that were later rolled back, or
data changes in an intermediate state of the transaction. It also
means
that in a simple query that scans all table/index data SQL Server may
lose the scan position, or you might end up getting the same row
twice.

"

You may find the details in the doc: InstantDoc #92888

You can replicate this behavior in SQL Server 2005/2000 using code
given in the above article and I believe it is public.

I hope it helps.
Oct 23 '07 #4
bmm
Hi again

Sory if my english is bad..

The situation is that I have a configuration table (CONF) which is accesed
often by severel programs (computers) on our network. Some of them are
WEB-applications, some are C# applications and some are manual used
query-analysers.

We noticed, that the C#-application sometimes doesn't get all the data from
the CONF-table when running the specific Stored procedure that reads data
from the CONF-table using NOLOCK. We couldn't get query-analyser to fail the
same way, when we used the same SP. (The SP also reads some other tables
beside the CONF-table. All the selects were using NOLOCK)

The problem was solved when we removed all the NOLOCKs from the SP.

I could understand if the SP returned too many rows in some cases, but not
too few....

/bjarni
"Erland Sommarskog" <es****@sommarskog.seskrev i en meddelelse
news:Xn**********************@127.0.0.1...
bmm (bm*************@comlog.dk) writes:
>I have a Store Procedure on a Sql Server 2000 Where I use the Table Hint
"NoLock" on all selects.

One of my clients (OleDbConnection from C#) doesn't get the same Result
Set as the others. The result Set should have 31 rows but this client
only gets 5!

When I remove all the "NoLocks" everything works fine. How can that be?

Maybe you could clarify a few things.

When you say "client" is that "client" as in "customer" or as in "client
computer"? Does the client that only gets five rows run the same
application
as those that get 31? If they run different applications, doethe other
application use a different API?

Is this behaviour constistent? That is, does it happen even if there is
no activity on the system, so that there are no locked rows?

Would it be possible for you to post the code of the procedure?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Oct 25 '07 #5
bmm (bm*************@comlog.dk) writes:
The situation is that I have a configuration table (CONF) which is accesed
often by severel programs (computers) on our network. Some of them are
WEB-applications, some are C# applications and some are manual used
query-analysers.

We noticed, that the C#-application sometimes doesn't get all the data
from the CONF-table when running the specific Stored procedure that
reads data from the CONF-table using NOLOCK. We couldn't get
query-analyser to fail the same way, when we used the same SP. (The SP
also reads some other tables beside the CONF-table. All the selects were
using NOLOCK)

The problem was solved when we removed all the NOLOCKs from the SP.

I could understand if the SP returned too many rows in some cases, but not
too few....
Still not very much information to work from. Are these web application
also using OleDbConnection?

Is this configuration table frequently updated? Or why the use of NOLOCK?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 25 '07 #6

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

Similar topics

9
2621
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
2
25419
by: Stephen McMahon | last post by:
Background: I am currently working on a mission critical web based application that is accessed 24 hours a day by users from just about every time zone. We use MS SQL Server as our database and...
4
14867
by: Eddie | last post by:
I wondering which one of the following I should use to get the best performance. 1. "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" OR 2. "WITH (NOLOCK)" I notice that when I use the #1...
6
8504
by: laurenq uantrell | last post by:
Is it possible to use With (NOLOCK) and With (READPAST) in the same SELECT query and what whould be the syntax? @param int SELECT myRow FROM dbo.myTable WITH (NOLOCK) WHERE
3
2619
by: Peter | last post by:
Hello all, I have the following t-sql batch: create procedure stp_test ( @p_date1 as datetime = null, @p_date2 as datetime = null )
3
1899
by: Hari | last post by:
Hi all, I need to get a part of string which follows a pattern 'addr=' For example: a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)"
318
12714
by: jacob navia | last post by:
Rcently I posted code in this group, to help a user that asked to know how he could find out the size of a block allocated with malloc. As always when I post something, the same group of people...
3
2134
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
1
3401
by: bhavinnaik | last post by:
Hi I am new to the IT enviro...although i've used QSL query for a while now but on simple or single queries. Here is the problem... I've got two queries looking at a set of tables to extract the...
0
7076
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...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
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...
1
6984
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...
0
7453
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...
0
5576
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,...
0
4670
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...
0
3162
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...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.