문제

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

도움이 되었습니까?

해결책

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

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Cheer AP

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top