Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 21, 2012

Row lock versus Page lock in SQL 2000.

Hi
We are facing an acute situation in our web-application. Technology is ASP.NEt/VB.NET, SQL Server 2000.

Consider a scenario in which User 1 is clicking on a button which calls a SQL stored procedure. This procedure selects Group A of records of Database Page1.

At the same time if User 2 also clicks the same button which calls same SQL stored procedure. This procedure selects Group B of records of Database Page1.

So, its the same Page1 but different sets of records. At this moment, both the calls have shared locked on the Page1 inside the procedure.

Now, in call 1, inside the procedure after selecting Group A of records, the next statement is and update to those records. As soon as update statement executes, SQL Server throws a deadlock exception as follows :

Transaction (Process ID 78) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction

We are able to understand why its happening. Its because, Group A and Group B of records are on the same Page1. But both the users have shared lock on the Page1. So, no one gets the exclusive lock in records for update, even though, the records are different.

How can I resolve this issue? How can I get lock on wanted rows instead of entire page?

Please advice. Thanks a bunch.

PankajWhy are you implementing *read* locks? Concurrent access via pessimistic locking is very low. Try implementing optimistic locking.

If you absolutely cannot implement optimistic locking (think 3 times about this before deciding on pessimistic locking), then you can make it so user 2 doesn't get to see the records at all and instead gets a message saying try back later.sql

Friday, March 9, 2012

Row Cannot be Located for Update Error

Can anyone offer any suggetions as to what could be causing this error
in my ASP. Please dont mind the newbie code, I'm still pretty green
at this:
*******ERROR*******
Microsoft Cursor Engine error '80040e38'
Row cannot be located for updating. Some values may have been changed
since it was last read.
-- ASP Code Causing the Trouble --
strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
= "&eventID
'Create the Recordset object and run SQL statement
Set logRS = Server.CreateObject ("ADODB.Recordset")
logRS.CursorLocation = adUseClient
logRS.Open strSQL, objConn,, adLockOptimistic
logRS("Completed") = True
logRS("CompletedBy") = secID
logRS("DateComplete") = Date()
logRS.Update <--ERROR HERE
'-- Trigger On Effected Table --
CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
FOR UPDATE
AS
Declare @.logID int,
@.quoteID int,
@.stepnum int,
@.userID int,
@.stepID int
Alter Table WorkLog Disable Trigger All
Set @.logID = (Select Log_ID From Inserted)
Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID = @.quoteID And Completed = 1)
Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
StepNum = @.stepnum + 1)
If @.stepID <> '65'
Begin
Update WorkLog
Set NextDue = 1
Where QuoteID = @.quoteID And
StepNum = @.stepnum + 1
Alter Table Quotes Disable Trigger All
Update Quotes
Set NextStep = @.userID
Where @.quoteID = quoteID
Alter Table Quotes Enable Trigger All
End
Alter Table WorkLog Enable Trigger AllHow about instead of opening up a recordset, you just execute an UPDATE
statement?
objConn.Execute("UPDATE ... WHERE ...")
The error sounds like you don't have a primary key, or there's not enough
information to identify the row based on the primary key. Since you use
SELECT *, I'm assuming the former. Are you familiar with primary keys? Is
it possible that there is more than one row WHERE QuoteID = ""eID&" And
stepID
= "&eventID ?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"belacyrf" <bela@.webnet-x.com> wrote in message
news:d0e7d44f.0405141126.20601f4@.posting.google.com...
> Can anyone offer any suggetions as to what could be causing this error
> in my ASP. Please dont mind the newbie code, I'm still pretty green
> at this:
> *******ERROR*******
> Microsoft Cursor Engine error '80040e38'
> Row cannot be located for updating. Some values may have been changed
> since it was last read.
> -- ASP Code Causing the Trouble --
> strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
> = "&eventID
> 'Create the Recordset object and run SQL statement
> Set logRS = Server.CreateObject ("ADODB.Recordset")
> logRS.CursorLocation = adUseClient
> logRS.Open strSQL, objConn,, adLockOptimistic
> logRS("Completed") = True
> logRS("CompletedBy") = secID
> logRS("DateComplete") = Date()
> logRS.Update <--ERROR HERE
> '-- Trigger On Effected Table --
> CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
> FOR UPDATE
> AS
> Declare @.logID int,
> @.quoteID int,
> @.stepnum int,
> @.userID int,
> @.stepID int
> Alter Table WorkLog Disable Trigger All
> Set @.logID = (Select Log_ID From Inserted)
> Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
> Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
> Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID => @.quoteID And Completed = 1)
> Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
> StepNum = @.stepnum + 1)
> If @.stepID <> '65'
> Begin
> Update WorkLog
> Set NextDue = 1
> Where QuoteID = @.quoteID And
> StepNum = @.stepnum + 1
> Alter Table Quotes Disable Trigger All
> Update Quotes
> Set NextStep = @.userID
> Where @.quoteID = quoteID
> Alter Table Quotes Enable Trigger All
> End
> Alter Table WorkLog Enable Trigger All

Row Cannot be Located for Update Error

Can anyone offer any suggetions as to what could be causing this error
in my ASP. Please dont mind the newbie code, I'm still pretty green
at this:
*******ERROR*******
Microsoft Cursor Engine error '80040e38'
Row cannot be located for updating. Some values may have been changed
since it was last read.
-- ASP Code Causing the Trouble --
strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
= "&eventID
'Create the Recordset object and run SQL statement
Set logRS = Server.CreateObject ("ADODB.Recordset")
logRS.CursorLocation = adUseClient
logRS.Open strSQL, objConn,, adLockOptimistic
logRS("Completed") = True
logRS("CompletedBy") = secID
logRS("DateComplete") = Date()
logRS.Update <--ERROR HERE
'-- Trigger On Effected Table --
CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
FOR UPDATE
AS
Declare @.logID int,
@.quoteID int,
@.stepnum int,
@.userID int,
@.stepID int
Alter Table WorkLog Disable Trigger All
Set @.logID = (Select Log_ID From Inserted)
Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID =
@.quoteID And Completed = 1)
Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
StepNum = @.stepnum + 1)
If @.stepID <> '65'
Begin
Update WorkLog
Set NextDue = 1
Where QuoteID = @.quoteID And
StepNum = @.stepnum + 1
Alter Table Quotes Disable Trigger All
Update Quotes
Set NextStep = @.userID
Where @.quoteID = quoteID
Alter Table Quotes Enable Trigger All
End
Alter Table WorkLog Enable Trigger All
How about instead of opening up a recordset, you just execute an UPDATE
statement?
objConn.Execute("UPDATE ... WHERE ...")
The error sounds like you don't have a primary key, or there's not enough
information to identify the row based on the primary key. Since you use
SELECT *, I'm assuming the former. Are you familiar with primary keys? Is
it possible that there is more than one row WHERE QuoteID = ""eID&" And
stepID
= "&eventID ?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"belacyrf" <bela@.webnet-x.com> wrote in message
news:d0e7d44f.0405141126.20601f4@.posting.google.co m...
> Can anyone offer any suggetions as to what could be causing this error
> in my ASP. Please dont mind the newbie code, I'm still pretty green
> at this:
> *******ERROR*******
> Microsoft Cursor Engine error '80040e38'
> Row cannot be located for updating. Some values may have been changed
> since it was last read.
> -- ASP Code Causing the Trouble --
> strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
> = "&eventID
> 'Create the Recordset object and run SQL statement
> Set logRS = Server.CreateObject ("ADODB.Recordset")
> logRS.CursorLocation = adUseClient
> logRS.Open strSQL, objConn,, adLockOptimistic
> logRS("Completed") = True
> logRS("CompletedBy") = secID
> logRS("DateComplete") = Date()
> logRS.Update <--ERROR HERE
> '-- Trigger On Effected Table --
> CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
> FOR UPDATE
> AS
> Declare @.logID int,
> @.quoteID int,
> @.stepnum int,
> @.userID int,
> @.stepID int
> Alter Table WorkLog Disable Trigger All
> Set @.logID = (Select Log_ID From Inserted)
> Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
> Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
> Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID =
> @.quoteID And Completed = 1)
> Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
> StepNum = @.stepnum + 1)
> If @.stepID <> '65'
> Begin
> Update WorkLog
> Set NextDue = 1
> Where QuoteID = @.quoteID And
> StepNum = @.stepnum + 1
> Alter Table Quotes Disable Trigger All
> Update Quotes
> Set NextStep = @.userID
> Where @.quoteID = quoteID
> Alter Table Quotes Enable Trigger All
> End
> Alter Table WorkLog Enable Trigger All

Row Cannot be Located for Update Error

Can anyone offer any suggetions as to what could be causing this error
in my ASP. Please dont mind the newbie code, I'm still pretty green
at this:
*******ERROR*******
Microsoft Cursor Engine error '80040e38'
Row cannot be located for updating. Some values may have been changed
since it was last read.
-- ASP Code Causing the Trouble --
strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
= "&eventID
'Create the Recordset object and run SQL statement
Set logRS = Server.CreateObject ("ADODB.Recordset")
logRS.CursorLocation = adUseClient
logRS.Open strSQL, objConn,, adLockOptimistic
logRS("Completed") = True
logRS("CompletedBy") = secID
logRS("DateComplete") = Date()
logRS.Update <--ERROR HERE
'-- Trigger On Effected Table --
CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
FOR UPDATE
AS
Declare @.logID int,
@.quoteID int,
@.stepnum int,
@.userID int,
@.stepID int
Alter Table WorkLog Disable Trigger All
Set @.logID = (Select Log_ID From Inserted)
Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID =
@.quoteID And Completed = 1)
Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
StepNum = @.stepnum + 1)
If @.stepID <> '65'
Begin
Update WorkLog
Set NextDue = 1
Where QuoteID = @.quoteID And
StepNum = @.stepnum + 1
Alter Table Quotes Disable Trigger All
Update Quotes
Set NextStep = @.userID
Where @.quoteID = quoteID
Alter Table Quotes Enable Trigger All
End
Alter Table WorkLog Enable Trigger AllHow about instead of opening up a recordset, you just execute an UPDATE
statement?
objConn.Execute("UPDATE ... WHERE ...")
The error sounds like you don't have a primary key, or there's not enough
information to identify the row based on the primary key. Since you use
SELECT *, I'm assuming the former. Are you familiar with primary keys? Is
it possible that there is more than one row WHERE QuoteID = ""eID&" And
stepID
= "&eventID ?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"belacyrf" <bela@.webnet-x.com> wrote in message
news:d0e7d44f.0405141126.20601f4@.posting.google.com...
> Can anyone offer any suggetions as to what could be causing this error
> in my ASP. Please dont mind the newbie code, I'm still pretty green
> at this:
> *******ERROR*******
> Microsoft Cursor Engine error '80040e38'
> Row cannot be located for updating. Some values may have been changed
> since it was last read.
> -- ASP Code Causing the Trouble --
> strSQL = "SELECT * FROM WorkLog WHERE QuoteID = ""eID&" And stepID
> = "&eventID
> 'Create the Recordset object and run SQL statement
> Set logRS = Server.CreateObject ("ADODB.Recordset")
> logRS.CursorLocation = adUseClient
> logRS.Open strSQL, objConn,, adLockOptimistic
> logRS("Completed") = True
> logRS("CompletedBy") = secID
> logRS("DateComplete") = Date()
> logRS.Update <--ERROR HERE
> '-- Trigger On Effected Table --
> CREATE TRIGGER UpdateNextDue ON [dbo].[WorkLog]
> FOR UPDATE
> AS
> Declare @.logID int,
> @.quoteID int,
> @.stepnum int,
> @.userID int,
> @.stepID int
> Alter Table WorkLog Disable Trigger All
> Set @.logID = (Select Log_ID From Inserted)
> Set @.quoteID =( Select QuoteID From WorkLog Where Log_ID = @.logID)
> Set @.stepID = (Select stepID From WorkLog Where Log_ID = @.logID)
> Set @.stepNum =( Select Max(StepNum) From WorkLog Where quoteID =
> @.quoteID And Completed = 1)
> Set @.userID =( Select UserID From WorkLog Where quoteID = @.quoteID And
> StepNum = @.stepnum + 1)
> If @.stepID <> '65'
> Begin
> Update WorkLog
> Set NextDue = 1
> Where QuoteID = @.quoteID And
> StepNum = @.stepnum + 1
> Alter Table Quotes Disable Trigger All
> Update Quotes
> Set NextStep = @.userID
> Where @.quoteID = quoteID
> Alter Table Quotes Enable Trigger All
> End
> Alter Table WorkLog Enable Trigger All

Wednesday, March 7, 2012

Rounding Error?

I'm passing a value from an ASP.net app to an sql stored procedure which stores it in a table.

Problem is if, for example, the value is 2.81 the value is ending up as 2.08999... in my table, but if i do say 6.3 it's fine.

Ive tried having the variable in asp and the field where its stored in sql as a number of types but all with the same result.

Any ideas?

Geoff.You should check the definition and precision of your database column.
Maybe change it from float to money.

Regards
Fredrik