Question

I have the SQL text "SELECT * FROM TABLE1 WITH (NOLOCK)".

Two questions:

  1. How do I make my TADOQuery use the NOLOCK hint without having to include that in the SQL text? I have literally thousands of TADOQuery's with their SQL dynamically built, and it would be difficult to add WITH (NOLOCK) to all of them, not to mention I use with with database platforms other than MSSQL. Is there a TADOQuery property?

  2. How do I achieve the same thing with a TADOTable? TADOTable's don't have any SQL, so how do I tell it to use the NOLOCK hint?

Thanks

Was it helpful?

Solution

if you use MS SQL, run below statement once on connection

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Cheer AP

OTHER TIPS

Hints are database specific, thereby you have to issue the proper one for each database supported. In some databases there's also nothing equivalent, for example Oracle does not allow anything alike (readers never block writers and writers never block readers, thereby no need).

IMHO you shouldn't use TADOTable components at all - anyway AFAIK you have no way to specify an hint for the generated query - which is far too generic anyway.

Also you should be VERY careful to use NOLOCK. It means READ UNCOMMITTED, aka dirty reads. You're bypassing transaction protection, and unless you have a very good reason to bypass it you shouldn't - the gain in performance may be not worth the loss in data integrity and consistency.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top