Rowlock V. Optimistic Concurrency

Feb 8, 2008

Hi,

Sql-Server 2000, 2005.
A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the
sql is generated on the fly by a tool and not easily changeable).
SELECT col1, col2 FROM mytab WITH (ROWLOCK) WHERE ...."

The select-clause runs for several minutes.
Another user fetches one of those rows and tries to update it. The
result is a lock timeout.
I suppose that the long running select-clause has put a shared lock on
the rows and the updater (exclusive-lock) will have to wait for the
long-running select and so the lock timeout is expiring.

Are all those rows "shared locked" until all are fetched?
Would there be any change if the "WITH (ROWLOCK)" is removed, isn't
although "shared lock" the default behaviour?
The "WITH (NOLOCK)" would probably help?
What about the definition of optimistic concurrency, shouldn't all
select-clauses contain "WITH (NOLOCK)" to allow an optimistic
concurrency scenario?

Regards Roger.

PS. Probably some misunderstanding from me here, but this should be
the right place to get it right.

View 8 Replies


ADVERTISEMENT

Optimistic Concurrency Help

Jun 1, 2007

Hi,I'm trying to implement Optimistic Concurrency in asp 2 but so far it has caused me nothing but problems.First, when doing an UPDATE I tried to use the primary key & a timestamp field which I had in SQL Express.. VS 2005 generated the stored procedures fine however when it came to the actual updating I think there was a problem with the conversion of the timestamp field when it was being stored in a text box (in a FormView control). So.. as a result that failed. And also I checked sooo many places online and haven't been able to find any examples of code where a timestamp was used with success in asp2.Next, I got ride of the timestamp type (in SQL Express database) and used a datetime and then.. I just implemented Optimistic Concurrency by passing in ALL the values (ie all the original values) like is proposed http://www.asp.net/learn/dataaccess/tutorial21vb.aspx?tabid=63 . This... works however I really do not want to have to pass in ALL these values (ie original and new).Ideally I would like to be able to use the primary key & the datetime field to handle the Optimistic Concurrency checks where only the original values of both those fields are passed back into the stored procedure. Now.. I tried this as well, but I kept getting an error that suggests that (for some reason) the FormView or DataSource is passing ALL the values (original & new) into the dataset as opposed to only the original primary key & datetime fields & the new set of values.Can ANYONE offer any help? I really would like not to have to pass in all these values.Thanks in advance! 

View 6 Replies View Related

How To Enable Optimistic Concurrency

Jul 25, 2006

I have a number of SqlDataSource objects in my application, which don't have Optimistic Concurrency option enabled. The SDS objects use custom Sql statements so I can no longer select the Advance button to enable Concurrent Concurrency.
How can I enable this option? Is there a designt ime property, and even a run time property that can be set?
The only method we have so far is to create a new SDS, with Optimistic Concurrency switched on, then copy and paste my custom Sql into it and rebind my components..
Any help on this matter is appreciated.
Regards,
Steven
 
 

View 2 Replies View Related

Msde And Optimistic Concurrency

Apr 2, 2006

hello allI am working with the visual studio web express using MSDE as sql server.Every thing is working fine with database except when working with optimistic concurrency.So if I have a GridView or FormView binded to a SqlDataSource that is configured to perform the concurrency, these controls can't perform the update to the database.From debugging, I found that the SqlDataSource Old Value Paramters always null after postback.Is this a bug in the WebExpress, or do I need to use the SqlExpress Edittion?Thanks in advance, and keep the good effort.Hesham

View 1 Replies View Related

Optimistic Concurrency Control Error

Jun 28, 2006

Hi,

I have a table X:
ID (PK, int, not null)
cstID(FK, int, not null)
Name( nvarchar(100),not null)
Desc( ntext, null)

I am using the table view in Enterprise manager, if I manually type in a new row, then I edit that row, setting "Desc" = NULL, then I delete that row (from within the table view) I get the error:

Data has changed since the results pane was last retrieved. Do you want to save your changes now? (Optimistic Concurrency Control Error)

Things to note:
There was a FTI on this table, I deleted it, didn't help.
No other process or users are editing/viewing this table
The error doesn't occur if edit any other column, just setting the "Desc" to NULL creates this error.

Some other tables in my DB exhibit this same behavior, but not all......I can't figure out what the heck is going on...can you?

View 3 Replies View Related

Insert Should Aquire Only Exclusive Rowlock. Why Does Insert Block Select With ( Updlock, Rowlock )?

Mar 12, 2007

Here is the situation i am stuck with, see the example first and below explained the problem:

-- 'SESSION A

create table foo (

id integer,

pid integer,

data varchar(10)

);

begin transaction

insert into foo values ( 1, 1, 'foo' )

insert into foo values ( 2, 1, 'bar' )

insert into foo values ( 3, 1, 'bozo' )

insert into foo values ( 4, 2, 'snafu' )

insert into foo values ( 5, 2, 'rimrom' )

insert into foo values ( 6, 2, 'blark' )

insert into foo values ( 7, 3, 'smeg' )

commit transaction

create index foo_id_idx on foo ( id )

create index foo_pid_idx on foo ( pid )

begin transaction

insert into foo values ( 9, 3, 'blamo' )

-- 'SESSION B

begin transaction

select id, data from foo with ( updlock, rowlock ) where id = 5;



-- Problem:

-- Uncommitted transaction in session A, with insert into table FOO, aquires lock on index foo_pid_idx which BLOCKS select with ( updlock, rowlock ) in session B.

-- Insert should aquire only exclusive rowlock. Why does insert block select with ( updlock, rowlock )?



Appreciate your help,

Rajesh.

View 5 Replies View Related

Optimistic Vs. Pessimistic Locking

Oct 19, 2006

I am confused, I'll admit that outright.

A lot of entries in these forums recommend optimistic locking for most cases. Well, I have a very simple case (like everyone else, I bet :-)) and it seems to me pessimistic locking is the right answer:

User A loads an item on screen for maintenance. When user B wants to load the same item on screen for maintenance, he/she should be presented with a message "Item in use by someone else". That way they know they can't perform maintenance on the item (as yet). This can be achieved with pessimistic locking, by locking the row that is being loaded for maintenance and only unlocking it after an update or after another item is loaded in maintenance. The lock would be in update mode. This way the record cannot be modified but queries (for reporting or lists) in other parts of the system would still work fine.

The alternative in this case would be to allow both users to load the item on screen for maintenance, allow both of them to make changes and allow both of them to save -- one of them will save, the other would be stopped and another message will pop up, "Item already changed". This can be acheived with optimistic locking, by just allowing the engine to do its job.

While both approaches work, I strongly consider the first one to be more user friendly. Noone looses any changes they made, they know they have to wait for the item to become available and everything's peachy (granted, loading the item on screen and then leaving for an extended lunch may trigger some unpleasant after effects :-)).

Apart from the pessimistic update mode lock in the first case, is there any other (read better, safer, recommended) way to achieve this?



Thank you,

View 5 Replies View Related

RowLock

Jul 18, 2001

Hello,

Is there any way to specify the sql server to use row level locking in transaction.

Thanks

Val

View 1 Replies View Related

RowLock

Jan 28, 2008

Advantage and disadvantage of using rowlock in sql server 2005.

View 4 Replies View Related

Rowlock With Inner Join

Oct 26, 2007

Him

I am trying to issue the following statement to lock a record with inner join but I have an error:-

SELECT amaster.acctno,bmaster.balance,bmaster.YEAR
FROM amaster [ROWLOCK] with (Xlock)
INNER JOIN bmaster
ON amaster.acctno = bmaster.acctno
WHERE (bmaster.YEAR = 2007) acctno = 10000100
ORDER BY amaster.acctno

The error:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "amaster.acctno" could not be bound.

Thanks

View 9 Replies View Related

XLOCK And ROWLOCK

Jul 20, 2005

Hello,I need to lock only one row with exclusive lock (nobody else can see ormodify this row), but when I use "with (xlock, rowlock)" it doesn't work.XLOCK always locks whole table.Can anybody help me?Thanks in advance.Magda

View 1 Replies View Related

Isolation Level VS With(nolock|rowlock)

May 22, 2008

Hello all.
I'm a litle confused about what's best to use, either isolation levels or locking per table.
Cause there are some queries in the stored procedures where I don't need locking i.e. when I check the status of client, but other queries where I do need locking like when I check the existence of a product.

What's best to use, can I combine both? Could you explain it thecnically?

lots of thanks in advance

View 1 Replies View Related

SQL Seems To Ignore UPDLOCK && ROWLOCK Hints

Dec 3, 2007



I've got a SELECT WITH (UPDLOCK, ROWLOCK) WHERE followed by an UPDATE WHERE statement. The results of the SELECT statement are deserialized in C# and updates are made to the deserialized object. Then the object is serialized back into the table with the UPDATE statement. I've got this code running within a transaction scope with the ReadCommited isolation level.

My service receives requests to update data and the requests can come in on different threads. What I'm seeing, is that once in a while, the log messages from my application indicate that two different threads are able to issue the above SELECT statement and both are receiving results. This is a problem since the thread that issues the last UPDATE will overwrite the changes made by the first. Each thread has its own connection and transaction scope.

I've researched all over the place and have tried a few different things, but all things point to the fact that query hints are just hints and that SQL may or may not pay attention to them. If that's the case, how am I suppose to perform a SELECT with the intention of updating so that no one else can do the same? I haven't tried table level locking, but I'd really like to avoid that if possible.

-Mike

View 4 Replies View Related

NOLOCK/ROWLOCK (good Or Bad Guys?)

Nov 9, 2007

Reading about avoiding deadlocks in SQL, I have found different opnions about whether using or not NOLOCK/ROWLOCK hints on SELECT/UPDATE/DELETE statements. I have several applications executing transactions on the same databases and tables, including inserts, updates and deletes. I wonder if by using NOLOCK/ROWLOCK I could decrease the chances of having deadlocks. At least using ROWLOCK on my update statements?. I just need some advice here.

Regards.

View 2 Replies View Related

SQL Server 2008 :: Update With Xlock / Rowlock And Read With Nolock

Feb 10, 2015

I have a stored procedure that updates a table. I also have an UDF that allows dirty reads (nolock).

What's the precedence level in SQL server? If I add xlock,rowlock to the update statement, will the dirty read wait for the update transaction to commit, or will it perform a dirty read regardless of the locking scheme in the update statement?

View 0 Replies View Related

SSIS Transaction Management && Strange Deadlock When Using XLOCK, ROWLOCK

Jun 7, 2007

I have a SSIS package that is run from one job, nowhere else. The package has TransactionOption NotSupported.



In the SSIS package I first have a sequence container that has TransactionOption Required (Serializable). The sequence container contains several Execute SQL tasks that access the same SQL Server 2005 database. The Execute SQL tasks have TransactionOption supported / Serializable. The first SQL statement is:



select p.column_name

from table_name p with (XLOCK, ROWLOCK)

where p.second_column_name = 'COLUMN_VALUE'



After this there are a couple of SQL tasks, and finally a task containing the following SQL:



select p.third_column_name

from table_name p

where p.second_colomn_name = 'COLUNM_NAME'



The idea is that the first query exclusively locks the row in the table_name-table for mutual exclusion purposes, i.e. so that if for some reason the SSIS package would be executed simultaneously two or more times, only one package execution could lock the row and proceed and the other executions will have to wait. There's an index on column second_column_name in the table to avoid the select locking other rows in addition to the required row.



Some questions:

1) Is it so in my setup that when SSIS runtime executes the sequence container it creates a transaction in the beginning of the sequence container and commits the transaction in the end of the sequence container? And in my setup the Execute SQL tasks in the sequence containar are executed under the same transaction?

2) I have a problem that the second query sometimes gives this error:"ErrorCode: -1073548784. ErrorDescription: Executing the query "XXXXX" failed with the following error: "Transaction (Process ID 73) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."

The 1st query has locked the row for the transaction. How can the second query be deadlocked, shouldn't the transaction have a lock on the row? I'd understand if the 1st query failed sometimes, but don't understand how the 2nd quey can fail.



r,

JM

View 3 Replies View Related

SQL Optimistic (all In One Table Split Into Two Table)

Dec 18, 2007

I having a bit of confuse here. Can you please help me?

I have about 5000 records all ready in oen table. Everything that I query is related to that table one way or the other. Now i having 2000 - 3000 more records to store in the database. In term of relation database then I can store the new data in a different table so I can can query it. Most of my queries are searching.

So the question is is this better to store the data in another table or should store everything in the old table? Thanks a lot in advance for your help. I really do appreciate that.

Maverick

View 2 Replies View Related

Concurrency In Asp.net

Oct 25, 2006

Hi everybody,I need to understand how concurrency excatly
work in asp.net. For example, I'm confused what happens if two users at
the same time try to access the same record in a table or even the same
variable. Do ASP.NET handle this , I mean by locking one user and
letting the other to have access  OR it's up to the programmer to write
some code to lock shared resources such as database , objects and
variables?If it's up to the programmer to do this task, I appreciate if you can show me an example that clarifies that.Thank you

View 2 Replies View Related

Concurrency, Have I Got This More Or Less Right?

Jul 23, 2005

Following on from a thread I started about "concurrency" (real-time-ishsystem), I thought I would play about to see if I could easily adapt my datamodel to take account of potential multi-user write conflicts. So, I wouldappreciate you checking my logic/reasoning to see if this kind of thingwill work. Below I have a stored procedure that will simply delete a givenrecord from a given table. I have appended a "_Written" counter to thecolumns of the table. Every time the record is written, the counter isincremented. Clients store the current _Written count in their objects andpass this in to any write procedure executed.The procedure explicitly checks the _Written count within the transaction tosee if it agress with the written count passed in by the client. If it doesnot, the client throws an error. Note I am explicitly checking the_Written count precisely so I can determine exactly why this operation mightfail, rather than checking @@ROWCOUNT after an update.Thanks.RobinCREATE PROCEDURE dbo.proc_DS_Remove_DataSet@_In_ID INTEGER,@_In_Written INTEGERASDECLARE @Error INTEGERDECLARE @WRITTEN INTEGERBEGIN TRANSACTIONSET @Error = @@ERRORIF @Error = 0BEGINSELECT @WRITTEN = _Written FROM MyTable WHERE ID = @_In_IDSET @Error = @@ERRORIF @WRITTEN <> @_In_WrittenBEGINRAISERROR ('10', 16, 1)SET @Error = @@ERRORENDENDIF @Error = 0BEGINDELETE FROM MyTable WHERE ID = @_In_IDSET @Error = @@ERRORENDIF @Error = 0COMMIT TRANSACTIONELSEROLLBACK TRANSACTIONRETURN @Error

View 5 Replies View Related

Concurrency

May 27, 2007

Do single commands (or stored procedures) execute concurrently, or they are executed one by one. How do you perform a lock during the execution of a command (or stored procedure).

View 3 Replies View Related

Object Concurrency

Jun 20, 2006

I have a user object that is stored in the session for each user but what if an administrator updates a certain user and I want to reflect the update to the user if they are logged in?One possible way of solving this is:Each time the user goes to a page, check the user table and compare the timestamp. That would mean if 30 users refresh the page..the db would hit 30 times lol. I don't think that would scale very well.Any ideas on how to solve this?

View 5 Replies View Related

UPDATE Concurrency?

Aug 4, 2006

I have a table where I count how many emails of a given type are sent out each day. This incrementing is wrapped in a sproc that either inserts a new row, or updates the existing row. The column that counts the value is named Count of type INT.
Below is the sproc, seems like a straightforward thing. However, I'm seeing email counts higher than they should be when there's a high number of concurrent executions of the sproc. I'm pretty sure it's not a problem in the calling code, so I'm wondering about the UPDATE statement, since it updates a column based on the value of the column. I would think this should work since it's wrapped in a SERIALIZABLE transaction, anybody have further insight?
SQL Server 2005 by the way.
Sean
CREATE PROCEDURE [dbo].[IncrementEmailCounter](    @siteId SMALLINT,    @messageType VARCHAR(20),    @day SMALLDATETIME) ASBEGIN    SET NOCOUNT ON;
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE    BEGIN TRANSACTION
    IF (SELECT COUNT(*) FROM EmailCount WHERE SiteId = @siteId AND MessageType = @messageType AND [Day] = @day) = 0        INSERT INTO EmailCount (SiteId, MessageType, [Day], [Count]) VALUES (@siteId, @messageType, @day, 1)    ELSE        UPDATE EmailCount SET [Count] = [Count] + 1 WHERE SiteId = @siteId AND MessageType = @messageType AND [Day] = @day
    COMMIT TRANSACTION    SET TRANSACTION ISOLATION LEVEL READ COMMITTEDEND

View 3 Replies View Related

Database Concurrency

Feb 17, 2007

I'm wondering whether the following code would work if users are RAPIDLY registering (assumption) WITH the same username.public bool UsernamExists(string username)
{
string sql = "SELECT true FROM [users] WEHRE username = @username;";
return Convert.ToBoolean(comm.ExecuteScalar());
}

public bool Signup(User user)
{
bool usernameExists = UsernameExists(user.Username);
if( usernameExists ) return false;

//update or insert sql for user etc blah blah
} If two users try to signup AT THE VERY SAME TIME (DOWN TO THE NANOSECOND), would this technique work? Do I have to wrap it in a transaction, stored procedure??  Thanks. 

View 8 Replies View Related

Concurrency Control

Apr 6, 2005

Hi! I'm building a web application with ASP.NET, and using MS SQL 2000 for my database server.
How should I do to guarantee the integrity of the data in spite of the concurrent access? Meaning... how can I make sure that more than 1 user can update 1 table at the same time, while no error will occur? Do I need to add some codes at my aspx file? Or do I need to do something to my database? Or do I not have to worry about it?
Thank you.

View 1 Replies View Related

Concurrency Issue

Sep 27, 1999

Can anyone help with concurrency issues. Small network and only one person at a time can log into the database.
It was originally written in MS Access and converted to SQL 7.0 with a VB front end.

Thanks,

Rick

View 1 Replies View Related

SQL Server 6.5 SMP Concurrency

Feb 2, 1999

We have two processors on which sql server was installed.

SMP Concurrency opion is -1. and process priority is 0.

The computer is dedicated to Sql server.

with the same setup, has any body faces any problem....?

some times suddenly system hangs... sql sever takes 99% cpu usage ...

Shall I run the SQL Executive, SQL Performance Monitor with this setup...?

will it afect the system...?

[ this kind of setup - those you experienced.. ]

please reply immediately....

thanks

Wincy

View 1 Replies View Related

SMP Concurrency Configuration

Mar 31, 1999

Hello,
SQL Server6.5 is installed on a dual processor computer. So can I make use of dual processors by setting SMP concurrency to -1 or 2.

I tried setting these values but failed to do so. Server is running at setting 1 always, irrespective of configured value.

Any suggestion???

Srini

View 3 Replies View Related

Concurrency Issues

Sep 6, 2004

Is there any way to get the sample below working so that both "threads" are guaranteed to get unique and incrementing values?

I'm suspecting the answer is no. You can use transactions on completely database oriented operations that read/write to a database and complete. But there aren't complete synchronization controls for operations like below that try to return a value to an outside process.


IF OBJECT_ID('SimpleTable') IS NOT NULL
DROP TABLE SimpleTable

CREATE TABLE SimpleTable (
A INTEGER
)
INSERT INTO SimpleTable (A) VALUES (1)

-- Run in one window
DECLARE @value INTEGER

BEGIN TRANSACTION
SELECT TOP 1 @value = A FROM SimpleTable
WAITFOR DELAY '00:00:05'
UPDATE SimpleTable SET A = @value + 1
COMMIT TRANSACTION

SELECT @value
SELECT A FROM SimpleTable

-- Run in a second window
DECLARE @value INTEGER

BEGIN TRANSACTION
SELECT TOP 1 @value = A FROM SimpleTable
UPDATE SimpleTable SET A = @value + 1
COMMIT TRANSACTION

SELECT @value
SELECT A FROM SimpleTable

View 7 Replies View Related

Concurrency Question

Oct 5, 2006

Suppose process A is updating record #1 in table T.

By default, can other processes read record #1 while the updating is in progress ??

If the answer is Yes, then which value can they see - the old one or the new one ?

Thank you in advance.

View 1 Replies View Related

Question About Concurrency

Aug 16, 2006

Did I understand correctly the Pesimistic access:
When we choose pessimistic access
-we lock all the rows of the table. right.
-other users still can access the table if they specify read only mode meaning if their intention is to only read the data and not modify it. am I right

Thanks for your help.

View 1 Replies View Related

Cursors And Concurrency

Sep 21, 2006

In a previous post, the theme of cursors and concurrency was touched as a secondary subject. I have a specific question about it as the primary one:

if we have
--------
create proc myProc
as
declare cursor for
select * from mytable
go
----------
if two or more clients(webpages for example)
execute myProc concurrently will the cursor be safe ? or would I have to make special arrangements, there are a couple of procs (that use cursors)that somebody else did and would not like to modify but we want to make the procs web available,

thank you

View 2 Replies View Related

Concurrency In Transaction

Aug 4, 2005

hi gurusthe scenarioFrontend - MS Access (not yet decided whether MDB or ADP)Backend - MS SQL Serverit is a conversion from MS Access backend to MS SQL Server Backend.Planning to create stored procedures for all the Inserts, Updates,Deletes and Business Rules / Validations wherever it is possible.the problemi am running in concurrency problem. the same classic scenario of twousers retrieving the same row (record) from the same table. it allowsboth the user to update the record, that is, the user who updates lasthas his changes saved though he retrieved that particular recordsecond.what i need is that the user who retrieved the record second shouldn'tbe able to update or delete the record when it is already retrieved byany other user.would appreciate if someone pointed me in the right direction to solvethe above problem, i know it is related to isolation property but amnot surethanx in advanceregardsbala

View 2 Replies View Related

Possible Concurrency Issues.

Apr 6, 2006

Hi,
I was wondering if it is possible to call a stored procedure from sql server 2005 (call it sp_1) that calls an assembly which takes a message, wraps it in soap and calls a webservice and waits for a reply from that webservice (the stored procedure is clr not t-sql). This WebService needs to then call sp_1 to perform some other tasks. Is this possible or does sp_1 need to have finished what it was doing before it can be called again.

I have been trying to do this and have received a number of errors one of which looks like;

'The context connection is already in use.'

Sorry if I haven't worded it very well, I will try to clear up any questions if you need me to.

Thanks
N

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved