Hi,
Whether NOLOCK is good or bad is completely subjective to what you are
trying to do. This will allow the data to be read from the table as it
currently stands. As you can handle the fact that data may change this
should not bother you (especially in a stateless environment). An
alternative to NOLOCK is READPAST. When this is applied it will skip over a
row that is locked by another transaction and only read committed records.
This may result in rows that you would ordinarily expect in the result set
to been missing. These lock hints at the end of the day are provided for
situations where locking will occur frequently/infrequently and there is no
other reasonable alternative.
One thing you should try and do is find out what is coursing the locking.
SQL Server has three levels of locks: Table, Page and Row. The first thing
is to determine which lock is being used has this might have a strong
bearing on your selection of a lock hint. For example if a table lock is
being applied there would be no point in using READPAST. In Enterprise
Manager open the server that is running you database then navigate to
<server>/Management/Current Activity/
Under there are two sub folders 'Locks/Process ID' and 'Locks / Objects'. In
Locks/process ID it will display the user coursing the blocking and the
user(s) who is being blocked. Drill down into the blocking 'spid' and you
will see a list of tables and the lock type that has been applied to it. If
you double click on the table it will show you the query been executed
against it.
One problem I come across is where a programmer starts a transaction when
the user clicks edit then save the information as they progress from one
form to another and only committing the transaction when the user click save
/ or rolling back on cancel. As a result this is completely dependant on the
user interaction. In some cases they have been know to leave there computer
on and go on holiday.
- Mike
---------------------------------------------------------------------------------
<a href="http://www.cogitar.net"> Cogitar Software. (
http://www.cogitar.net ) </a>
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://shop-dominion.com (senery landscape pictur gallery)
---------------------------------------------------------------------------------
"jason" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have found one other thread on this topic, but the responses only
> described "bad" ways to fix the problem. I'd like to know if there are
> any "good" ways to fix the problem 
>
> I have a class with a private, instance-level SqlDataReader reference
> (so it's not being shared by multiple objects at runtime). That
> SqlDataReader is only used to ExecuteReader once, and then build a
> DataTable out of the results. However, we occasionally get Deadlocks on
> the READER when the ExecuteReader is attempting this read.
>
> The "bad" fix that I read was to change the reader characteristics to
> NOLOCK to allow dirty reads. This really isn't that bad, actually,
> because I only care about the data as it was at the moment of
> execution, if it changes after that, It will be caught in a subsequent
> execution of this method.
>
> But, are there any "good" ways to fix this issue?
>
> Thanks for any help,
>
> Jason
>