Ask a Question related to Coldfusion Database Access, Design and Development.
-
JoeD #1
Locking A Query?
Greetings. I need some feedback on using cflock with a query. I essentially
want to single thread just one piece of code (a query) on a page.
The query is a SQL stored procedure that does this:
1. Select an id from the next available record in the table.
2. Update that record (to make it no longer available).
3. Return the results of that record.
This happens pretty quick, but if two users hit the page at exactly the same
time, they can both get the same id. The update doesn't happen before the next
user runs executes the first select statement. Obviously, that's no good.
My questions: Would wrapping the query in cflock single-thread that code and
eliminate this issue (by forcing the query to complete for one user before a
second user can execute that query)?
Are there better solutions? Should I instead be looking at the stored proc by
changing the transaction isloation level?
Oh, yeah ... we're running CFMX, SQL 8, IIS on Windows Server 2003.
TIA.
joe
JoeD Guest
-
SQL Server Locking
I have an application that allows users to select the next person in a table based on a callback time and an InUse bit field. It is critical that... -
Need Help with Locking
I need help with understanding about locking. I have my DSN created as Application Variable . I want to lock a transaction in one of the module to... -
Query of Queries on query New type query
In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could... -
File locking in XP
The issue i'm experiencing may be more related to XP Pro than with Illustrator itself, but it only seems to be affecting Illustrator EPS files... ... -
DB2 locking UDF dll
Meg wrote: Which version of db2 are you using? For v8, try set KEEP_FENCED to no (db2 update dbm cfg using KEEP_FENCED NO). This way, the fenced... -
Sojovi #2
Re: Locking A Query?
Always is better put the DB operations in a stored procedure, the reasons are
well known. Using CFLOCK is a solution but you are not really locking the DB,
only a portion or CF code.
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
SELECT ..... (Select an id from the next available record in the table.)
UPDATE ..... (Update that record (to make it no longer available).
SELECT ...... (Return the results of that record.)
COMMIT TRANSACTION
Regards
Sojovi Guest
-
JoeD #3
Re: Locking A Query?
Thanks Sojovi -
I was thinking this must be so. SQL warns of using serializable isloation
because of performance hit, but it's most important to get it correct, even if
performance has to suffer a bit.
Is it safe to assume that modifying the isolation level in the stored proc is
still more efficient than using cflock?
jd
JoeD Guest
-
Sojovi #4
Re: Locking A Query?
The point is : With CFLOCK you are locking the portion of CF code beetwen begin
and end tag, but you are not really locking the DB, because if at the same time
CF is processing the CFLOCK somebody using the SQL query analizer modifies that
records involved, you'll have a consistency problem.
But if you want to lock more code than only the SQL statements you'll need to
use CFLOCK (besides SET ISOLATION LEVEL).
With you SET ISOLATION LEVEL SERIALIZABLE you are sure that nobody can access
the records involved in the opened transaction.
Regards
Regards
Sojovi Guest
-
JoeD #5
Re: Locking A Query?
Gotcha. That makes sense, because if I just set the isolation level to
serializable without using cflock, I get deadlocks. I'm hoping that setting
the isolation level to serializable in SP and locking the CF code with cflock,
I'll get the results I hope for.
Thanks for your help.
best,
joe
JoeD Guest



Reply With Quote

