|
I think they look like the nose holes of that fat cop in Simpson...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Take a look at the Service Broker[^] in SQL Server 2005. It looks like queues might do what you're looking for, specifically using the receive[^] command in conjunction with create queue.[^]. The queue will execute only one command at a time, so just add the appropriate sp calls to it, unless you could potentially be getting the same commands (which you want to block) from parts of the code you don't control, in which case the whole thing is moot.
|
|
|
|
|
What exactly are you doing that requires a critical section!? All operations on data within the scope of a transaction is by definition atomic.
If you are trying to execute code of some sort that really doesn't adhere to the rules of MSSQL/ACIDness, such as calling into .NET assemblies, then you'll have to handle synchronization in the .NET assemblies.
However, pay attention to what you're doing. Have you any idea what happens if the SQL engine is blocked by external code, possibly indefinitely, by a dead lock introduced by the external assembly? I have no idea, but I reckon it's bad for apps and database manager...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Jörgen Sigvardsson wrote: All operations on data within the scope of a transaction is by definition atomic.
Atomic yes, but not necessarily serializable, which seems to be what the OP is after. That depends on the isolation level of the transaction.
|
|
|
|
|
What I want in the transaction:
1. Check if a database record's status field is "pending".
2. If it is, then set status field to "processing", then process it. Otherwise, don't do anything.
3. After processing, set the status field to "processed".
If the above code is in a "critical section", then I can guarantee only one client is processing a record. I thought putting the code within a transaction will solve the problem. Apparently not.
|
|
|
|
|
I think I just heard the '70s call and they want the term batch processing brought back.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Chris Meech wrote: they want the term batch processing brought back.
I hardly noticed they were gone. When did that happen? For how long?
|
|
|
|
|
Would it help to set the Isolation Level for the transaction to Serializable[^]? I would not suggest doing this a lot, as it seems to me that it would cause a performance hit, but for this critical operation it might make sense.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
modified on Friday, December 18, 2009 12:38 PM
|
|
|
|
|
Roger Wright wrote: I would suggest doing this a lot, as it seems to me that it would cause a performance hit
I think you mean "would not suggest" here.
|
|
|
|
|
Oops... You're entirely correct!
There's cow-orkers milling about this place, so I had to type fast...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
and you probably need more time to get used to the new monitor...
|
|
|
|
|
That's at home, and yes, it's taking some getting used to.
I never realized just how wrong it looks to have square cards for solitaire! Worse, I think a recent Windows Update must have made it harder; I haven't won a game in days!!!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Roger Wright wrote: Would it help to set the Isolation Level for the transaction to Serializable?
That's exactly what was suggested by our DBA. Howver, there is still a chance to screw up. Here is what is within the transaction:
1. Check if the record's status field is "pending".
2. If it is, then set it to "processing" and process it, otherwise return.
By reading the documentation about "serializable", it seems possible for two different clients to find the status field to be "pending", and each setting it to "processing" and each processing the same record.
However, setting isolation level to "seriablizable" greatly reduced the chance of two clients processing the same record.
Let me know if I am wrong on this. Thanks.
|
|
|
|
|
I suspect an UPDATE could be of help, since they are atomic, much like an interlocked increment.
UPDATE table SET status = 'processing' WHERE status = 'pending' AND PrimaryKey = @value;
if row count > 0
-- Do the processing
else
-- Some other client is processing...
end if
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Ok, this could be another solution, and simpler, too. Thanks.
|
|
|
|
|
Yup, much easier!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
According to MSDN,
Statements cannot read data that has been modified but not yet committed by other transactions.
No other transactions can modify data that has been read by the current transaction until the current transaction completes.
Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.
It sounds to me like you would be fairly safe with this setting. Certainly it would be safer than the default.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Hi All
Question move from C/C++/MFC Message Board to here.
I have a problem to use syntax of MSSQL.I use this syntax
use databasename
it is not working for me.I check out through this code
SELECT db_name()
then result show MASTER.
Can any one give me tips where i wrong to use syntax.
Plz help me
|
|
|
|
|
If you write
use databasename it will throw error
Msg 207, Level 16, State 1, Line 1<br />
Invalid column name 'databasename'.
But if you write
use master it will say
Command(s) completed successfully.
Niladri Biswas
|
|
|
|
|
if i use
use master
And i want to create some table in different database then what i will do?
|
|
|
|
|
Dear All,
I use SQL Server 2005.
I want to creat Folder If have that folder name ready I want to rename it or delete old folder.
About File is the same.
Have any command for do it ?
Thanks for help....
VB.Net
|
|
|
|
|
You need to use xp_cmdshell, but you will probably have permissioning problems! Why do file activities from sql server?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I believe this can be done via
xp_cmdshell
In the below example I am creating a directory initially and next time if such a directory is found, I will rename that
declare
@cmdpath nvarchar(60)
, @Location nvarchar(100)
, @message nvarchar(max)
set @Location = N'C:\NewFolder'
set @cmdpath = 'MD '+ @Location
create table #result(result nvarchar(255))
insert into #result (result) exec master.dbo.xp_cmdshell @cmdpath
select @message = ISNULL(@message + ' - ','') + result from #result where result is not null
if(@message is not null)
begin
EXEC xp_cmdshell 'RENAME C:\NewFolder RenamedFolder'
end
select @message
drop table #result
For more info you can visit
a) Using xp_cmdshell[^]
b) xp_cmdshell[^]
Niladri Biswas
|
|
|
|
|
Why are you using SQL Server to interact with the file system, this is generally not recommended as it exposes the file system to database users. Most server environments will not allow that.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
thanks.
the reason is that the data in backup to txt file
so some have to rename, delete or create new.
about Folder when delete it ask are you sure (Y/N)?
how can type Y ?
VB.Net
|
|
|
|