Transaction deadlock

I

Ivan

Hi All,

Does anyone know how to prevent dead lock when
selecting records within Transaction??

Let me describe abit clear.
I created & open a transaction and before i commit/ rollback the transaction
i have to select few records within the same table
but the problem is once i execute a select sql statement for serveral times
(usually more than 2 times)... the select sql will be hold and the whole
application will be hung...
I guess the reason is because the transaction haven't finished
and as a result the select sql should be on queue

I have tried various solutions like changing the transaction level ... but
none of them work as needed

so.. please tell me if anyone know the solutions... thanks to all

Ivan
 
M

Miha Markic [MVP C#]

Hi Ivan,

Are you executing select within the same transaction or are you using
another connection/transaction?
Which database are you using?
 
M

Mary Chipman

One thing you might try is to execute the SELECT with the nolock hint.
That should give you the uncommitted dirty read of the rows, if that
is what you are looking for.

--Mary
 
I

Ivan

Hi Mary,

Thanks for your reply...
actually, what do u mean the nolock hint... I don't quite understand...

btw... i found a solution for my situation...
which is, if i don't execute 2 same (exactly the same) SELECT statement..
the deadlock won't happen... however, i still wonder how to fix it...
coz i 'm sure i'll face the similar situation again later....

Ivan
 
M

Mary Chipman

The "Locking Hints" topic in SQL Books Online explains the different
kinds of hints. Basically your Select statement looks like this:

SELECT <field list> FROM <tablename> WITH (NOLOCK)

But what you get is what's called a dirty read, or data that has not
been committed. So if you issue it in the middle of a transaction
against rows that have been updated but not committed yet, you'll see
data that may or may not actually end up in the database. OTOH, this
query won't honor any xlocks held by other transactions, either.

--Mary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

T-SQL vs ADO.NET Transaction? 3
Transaction 4
Deadlock error 1
transaction problems 2
Transaction deadlock on inserting into a table 49
SQL Server transaction problem 5
BEGIN TRANSACTION problem 7
Transaction Scope 5

Top