Thursday, March 22, 2012
deadlock problem
occassionally getting into a deadlock situation.
I have used DBCC TraceOn (-1,1204) to trace the problem and have had
moderate success. However, I have hit a particular deadlock that I just
don't understand and was hoping someone here may be able to help.
The two sps in question are Item_I and Item_DNPK.
The output from DBCC Trace (see below) tells me that SPID 60 (see red text)
has an exclusive (X) lock on the Item table index (KEY: 10:613577224:1 is a
clustered index XPKItem). SPID 60 is currently deadlocked at line 29 of
Item_I. Line 29 is the very first transaction in this sp.
The other client, SPID 56 (see green text) has a Range-Shared-Update lock on
the same resource as SPID 60 and is currently deadlocked at line 60 of
Item_DNPK. Line 60 is the very first meaningful transaction in this sp (not
counting declares and create operations on #temp tables).
The deadlock is, I think, occurring because SPID 60, which has an X lock on
the resource, is waiting for a Range-Insert-Null lock (see maroon text),
while SPID 56 is waiting for a Range-S-U lock on the same resource.
What I don't understand is why there is a deadlock in this case; with one
resource? Also, how can I prevent it, given that the lines in question are
right at the beginning of the transactions in the respective sps?
Any help would be very much appreciated
Adrian
Output of DBCC TraceOn (1204) for the deadlock described above::
2006-02-21 14:25:06.21 spid4
2006-02-21 14:25:06.21 spid4 Node:1
2006-02-21 14:25:06.21 spid4 KEY: 10:613577224:1 (100095e758e0)
CleanCnt:1 Mode: X Flags: 0x0
2006-02-21 14:25:06.21 spid4 Grant List 0::
2006-02-21 14:25:06.21 spid4 Owner:0x42be3fe0 Mode: X Flg:0x0
Ref:0 Life:02000000 SPID:60 ECID:0
2006-02-21 14:25:06.21 spid4 SPID: 60 ECID: 0 Statement Type: INSERT
Line #: 29
2006-02-21 14:25:06.21 spid4 Input Buf: RPC Event: dbo.Item_I;1
2006-02-21 14:25:06.21 spid4 Requested By:
2006-02-21 14:25:06.21 spid4 ResType:LockOwner Stype:'OR' Mode:
Range-S-U SPID:56 ECID:0 Ec:(0x44111368) Value:0x42bd7920 Cost:(0/0)
2006-02-21 14:25:06.21 spid4
2006-02-21 14:25:06.21 spid4 Node:2
2006-02-21 14:25:06.21 spid4 KEY: 10:613577224:1 (ffffffffffff)
CleanCnt:1 Mode: Range-S-U Flags: 0x0
2006-02-21 14:25:06.21 spid4 Grant List 0::
2006-02-21 14:25:06.21 spid4 Owner:0x42bd85a0 Mode: Range-S-U Flg:0x0
Ref:0 Life:02000000 SPID:56 ECID:0
2006-02-21 14:25:06.21 spid4 SPID: 56 ECID: 0 Statement Type: INSERT
Line #: 60
2006-02-21 14:25:06.21 spid4 Input Buf: RPC Event: dbo.Item_DNPK;1
2006-02-21 14:25:06.21 spid4 Requested By:
2006-02-21 14:25:06.21 spid4 ResType:LockOwner Stype:'OR' Mode:
Range-Insert-Null SPID:60 ECID:0 Ec:(0x4428D368) Value:0x42bd29e0
Cost:(0/214)
2006-02-21 14:25:06.21 spid4 Victim Resource Owner:
2006-02-21 14:25:06.21 spid4 ResType:LockOwner Stype:'OR' Mode:
Range-S-U SPID:56 ECID:0 Ec:(0x44111368)See if this helps
http://sql-server-performance.com/deadlocks.asp
Madhivanan|||Please post the queries.
ML
http://milambda.blogspot.com/|||Here are the two queries involved in the deadlck I am referring to:
Query 1 - sp Item_DNPK (I have left some of this stored proc out just
because it is very long. My deadlocking is happening on the Insert so I
don't think the rest of the sp (after this Insert) is relevant. If you think
it will help, I can post it as well):
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ --SERIALIZABLE--
BEGIN TRAN
CREATE TABLE #Temp (MimeElementKey int)
-- primary key has to exist in order to prevent the subsequent deletes
from hanging
CREATE TABLE #Temp2 (ItemKey int not null , ParentKey int,
RecursionDepth int not null,
PRIMARY KEY CLUSTERED
(
[ItemKey],
[RecursionDepth]
))
-- get the dependent items of the initial item being deleted
INSERT INTO #Temp2
SELECT ItemKey, ParentKey, @.RecursionDepth
FROM [dbo].[Item] WITH (UPDLOCK,HOLDLOCK)
WHERE ParentKey = @.aItemKey
END
Query 2: Item_I:
CREATE PROC [dbo].[Item_I]
----
--
-- Schema Version : 2.2 Build 198 Revision 0
-- Date Generated : Mon Feb 20 09:56:52 2006
-- Author : Generated from schema stored procedure template 'SP_I'
-- Description : Generic identity based insert stored procedure for
table 'Item'
-- Returns : New Identity Key if successful or negative error
number
----
--
@.aItemTypeKey int ,
@.aParentKey int ,
@.aItemPartitionKey int ,
@.aOwnerKey int ,
@.aExternalKey sql_variant ,
@.aName nvarchar(256) ,
@.aDescription nvarchar(256) ,
@.aInternal varbinary(100) ,
@.aIsLeaf bit = 0,
@.aIsDeleted bit = 0,
@.aCreatedOn datetime ,
@.aModifiedOn datetime
AS
BEGIN
DECLARE @.Result int
SET NoCount ON
INSERT INTO [dbo].[Item]
(
ItemTypeKey,
ParentKey,
ItemPartitionKey,
OwnerKey,
ExternalKey,
Name,
Description,
Internal,
IsLeaf,
IsDeleted,
CreatedOn,
ModifiedOn
)
VALUES
(
@.aItemTypeKey,
@.aParentKey,
@.aItemPartitionKey,
@.aOwnerKey,
@.aExternalKey,
@.aName,
@.aDescription,
@.aInternal,
@.aIsLeaf,
@.aIsDeleted,
@.aCreatedOn,
@.aModifiedOn
)
IF (@.@.Error = 0)
BEGIN
SELECT @.Result = @.@.Identity
END
ELSE
BEGIN
SELECT @.Result = -@.@.Error
END
RETURN @.Result
END
"ML" <ML@.discussions.microsoft.com> wrote in message
news:D0BAC95E-35B8-47A2-9F51-2BF174E5EF0F@.microsoft.com...
> Please post the queries.
>
> ML
> --
> http://milambda.blogspot.com/|||Comments inline:
> SET TRANSACTION ISOLATION LEVEL REPEATABLE READ --SERIALIZABLE--
Repeatable read? Is there another reason for this isolation level? As far as
I see it you could just use defaults here (READ COMMITED).
> BEGIN TRAN
> CREATE TABLE #Temp (MimeElementKey int)
> -- primary key has to exist in order to prevent the subsequent deletes
> from hanging
> CREATE TABLE #Temp2 (ItemKey int not null , ParentKey int,
> RecursionDepth int not null,
> PRIMARY KEY CLUSTERED
> (
> [ItemKey],
> [RecursionDepth]
> ))
> -- get the dependent items of the initial item being deleted
> INSERT INTO #Temp2
> SELECT ItemKey, ParentKey, @.RecursionDepth
> FROM [dbo].[Item] WITH (UPDLOCK,HOLDLOCK)
The HOLDLOCK hint instructs the procedure not to release the lock until it
ends. As I see it you select a set of values here and store them in a local
temporary table, I guess you make a few changes, then update the values
appropriately or what? Could you do these in a single update statement? It
would really help if we could see the rest of the procedure here - especiall
y
the part where the explicit lock is acquired.
Also try adding the ROWLOCK hint.
> WHERE ParentKey = @.aItemKey
> END
The other procedure looks OK to me. It's a simple insert procedure, and has
little or no room for improvement. I, personally, prefer the INSERT...SELECT
syntax to INSERT...VALUES, but I've never heard that choosing either one
would affect locking.
ML
http://milambda.blogspot.com/|||Thanks for the reply.
I tried these two isolation levels (REPEATABLE READ and SERIALIZABLE), but
they don't seem to make a dramatic difference. I'm a little in the dark
ragarding this deadlock, so I must admit that I don't really know whether
READ REPEATABLE is better than READ COMMITTED or not.
The rest of this stored procuder involves several (7 or 8) different
delete/update queries which themselves were involved in earlier deadlocks.
It is for that reason I had started introducing these non-default isolation
levels. Again, though, I am largely driving by the seat of my pants, here;
no explicit reason for having done that.
The reason for the temp table is actually this: my schema is represented as
meta data within several tables and I need to delete a hierarchy of items
defined within this meta schema. To do this, I recurse the sp looking for
children of items at each level. I place the identifiers of all affected
items in the #temp table and then, as I come out of the recursion, I delete
and update various aspects of my schema to delete the children in a clean
and orderly fashion. The semantics of the sp may not make much sense to you
since the rest of the schema is not known to you. IF you have any questions,
though, I will be happy to try and work through them with you.
Thanks for your help in looking into this.
Here is the rest of the sp:
CREATE PROC [dbo].[Item_DNPK]
----
--
-- Schema Version : 2.2 Build 198 Revision 0
-- Date Generated : Mon Feb 20 09:56:52 2006
-- Author : APD
-- Description : Cascade primary key based delete stored procedure for
table 'Item'
-- Recursively calls into itself deleting all children of
the
-- item passed in as the parameter
-- Returns : Zero if successful or negative error number
-- Returns : and List of dependent items that were deleted during
the cascade
----
--
@.aItemKey int,
@.RecursionDepth int = 0
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ --SERIALIZABLE--
DECLARE @.IsLocalTran bit
DECLARE @.Result int
-- This procedure is recursive; keep track of the depth of recursion
SELECT @.RecursionDepth = @.RecursionDepth + 1
IF (@.@.TranCount = 0)
BEGIN
SET @.IsLocalTran = 1
BEGIN TRAN
END
ELSE
BEGIN
SET @.IsLocalTran = 0
END
SET @.Result = IsNull(Object_Id('tempdb..#Temp'), 0)
IF ((@.Result > 0) AND (@.RecursionDepth = 1))
BEGIN
DROP TABLE #Temp
END
-- A temporary table to hold the cascaded item Ids for later deletion
SET @.Result = IsNull(Object_Id('tempdb..#Temp2'), 0)
IF ((@.Result > 0) AND (@.RecursionDepth = 1))
BEGIN
DROP TABLE #Temp2
END
-- for the first entry, create holding tables
IF (@.RecursionDepth = 1)
BEGIN
CREATE TABLE #Temp (MimeElementKey int)
-- primary key has to exist in order to prevent the subsequent deletes
from hanging
CREATE TABLE #Temp2 (ItemKey int not null , ParentKey int,
RecursionDepth int not null,
PRIMARY KEY CLUSTERED
(
[ItemKey],
[RecursionDepth]
))
-- get the dependent items of the initial item being deleted
INSERT INTO #Temp2
SELECT ItemKey, ParentKey, @.RecursionDepth
FROM [dbo].[Item] WITH (UPDLOCK,HOLDLOCK)
WHERE ParentKey = @.aItemKey
END
ELSE
BEGIN
-- get the dependent items of the items at the previous recursion level
INSERT INTO #Temp2
SELECT i.ItemKey, i.ParentKey, @.RecursionDepth
FROM [dbo].[Item] i WITH (UPDLOCK,HOLDLOCK)
JOIN #Temp2 t WITH (NOLOCK)
ON i.ParentKey = t.ItemKey
WHERE t.RecursionDepth = @.RecursionDepth-1
END
-- if the "get" of dependent children returned a non-zero number of items,
recurse to get their children
IF (SELECT @.@.ROWCOUNT) > 0
BEGIN
-- get these children to delete as well
EXEC Item_DNPK null, @.RecursionDepth
END
-- delete all items and clean up links as a result of these deletions
INSERT INTO #Temp
SELECT ME.[MimeElementKey]
FROM [dbo].[MimeElement] ME
JOIN [dbo].[Property] P
ON ME.[MimeElementKey] = P.[MimeElementKey]
WHERE P.[ItemKey] in (SELECT ItemKey FROM #Temp2 WITH (NOLOCK) WHERE
RecursionDepth = @.RecursionDepth)
IF (@.@.Error = 0)
BEGIN
DELETE [dbo].[Property]
WHERE [ItemKey] in (SELECT ItemKey FROM #Temp2 WITH (NOLOCK) WHERE
RecursionDepth = @.RecursionDepth)
END
IF (@.@.Error = 0)
BEGIN
DELETE [dbo].[MimeElement]
FROM [dbo].[MimeElement] ME
JOIN #Temp WITH (NOLOCK)
ON ME.[MimeElementKey] = #Temp.[MimeElementKey]
DELETE FROM #Temp
END
IF (@.@.Error = 0)
BEGIN
/* DELETE [dbo].[Link]
FROM [dbo].[Link] l
JOIN #Temp2 t WITH (NOLOCK) ON l.[SourceItemKey] = t.ItemKey
WHERE RecursionDepth = @.RecursionDepth
END
IF (@.@.Error = 0)
BEGIN
DELETE [dbo].[Link]
FROM [dbo].[Link] l
JOIN #Temp2 t WITH (NOLOCK) ON l.[TargetItemKey] = t.ItemKey
WHERE RecursionDepth = @.RecursionDepth */
DELETE [dbo].[Link]
WHERE [SourceItemKey] in (SELECT ItemKey FROM #Temp2 WITH (NOLOCK) WHERE
RecursionDepth = @.RecursionDepth)
OR [TargetItemKey] in (SELECT ItemKey FROM #Temp2 WITH (NOLOCK) WHERE
RecursionDepth = @.RecursionDepth)
END
IF (@.@.Error = 0)
BEGIN
UPDATE [dbo].[Property]
SET [ReferenceTargetItem] = NULL
FROM [dbo].[Property] p
JOIN #Temp2 t WITH (NOLOCK) ON p.[ReferenceTargetItem] = t.ItemKey
WHERE RecursionDepth = @.RecursionDepth
END
IF (@.@.Error = 0)
BEGIN
UPDATE [dbo].[Item]
SET [ParentKey] = NULL
FROM [dbo].[Item] i
JOIN #Temp2 t WITH (NOLOCK) ON i.[ParentKey] = t.ItemKey
WHERE RecursionDepth = @.RecursionDepth
END
IF (@.@.Error = 0)
BEGIN
DELETE [dbo].[Item]
FROM [dbo].[Item] i
JOIN #Temp2 t WITH (NOLOCK)
ON i.ItemKey = t.ItemKey
WHERE t.RecursionDepth = @.RecursionDepth
END
IF (SELECT @.RecursionDepth) = 1
BEGIN
-- delete the primary item passed in as a parameter
IF (@.@.Error = 0)
BEGIN
-- put it in #Temp2 so we can return it in the "cascadedDeletedItems"
resultset
INSERT INTO #Temp2
SELECT i.ItemKey, i.ParentKey, @.RecursionDepth
FROM [dbo].[Item] i -- WITH (NOLOCK)
WHERE i.ItemKey = @.aItemKey
exec Item_D1PK @.aItemKey
END
if (@.IsLocalTran = 1)
BEGIN
IF (@.@.Error = 0)
BEGIN
COMMIT TRAN
END
ELSE
BEGIN
ROLLBACK TRAN
END
END
SELECT @.Result = -@.@.Error
-- return the items affected by this query
SELECT distinct ItemKey FROM #Temp2
RETURN @.Result
END
END
GO
"ML" <ML@.discussions.microsoft.com> wrote in message
news:1D228D99-FB06-4FB4-AEC2-24653942A8B4@.microsoft.com...
> Comments inline:
>
> Repeatable read? Is there another reason for this isolation level? As far
> as
> I see it you could just use defaults here (READ COMMITED).
>
> The HOLDLOCK hint instructs the procedure not to release the lock until it
> ends. As I see it you select a set of values here and store them in a
> local
> temporary table, I guess you make a few changes, then update the values
> appropriately or what? Could you do these in a single update statement? It
> would really help if we could see the rest of the procedure here -
> especially
> the part where the explicit lock is acquired.
> Also try adding the ROWLOCK hint.
>
> The other procedure looks OK to me. It's a simple insert procedure, and
> has
> little or no room for improvement. I, personally, prefer the
> INSERT...SELECT
> syntax to INSERT...VALUES, but I've never heard that choosing either one
> would affect locking.
>
> ML
> --
> http://milambda.blogspot.com/|||Before I read through the entire procedure - is there a tree or a hierarchy
involved in these deletes?
This could be optimized, take a look at this example:
http://milambda.blogspot.com/2005/0...or-monkeys.html
Deletes require exclusive locks - you should make the delete procedure as
concise as possible - maybe even by building the list outside of a
transaction, and only beginning an explicit transaction just before the
actual delete statement. The delete will block other users anyway, so make i
t
as short as possible.
ML
http://milambda.blogspot.com/|||Yes. Typically an item in the item table has reference to it's parent which
is another item in the item table. The relationship from parent to children
is one to many. A row representing an item in the item table has references
to other tables that define things like properties and property types, etc.
Essentially, then, the hierarchy is to determine all the children of the
item whose id is passed in as a parameter to the sp, and recursively do that
for all those children until the end of the line is reached
I hope this answers your question.
Adrian
"ML" <ML@.discussions.microsoft.com> wrote in message
news:1DECC75A-38CD-40AB-BC63-50FD758231C9@.microsoft.com...
> Before I read through the entire procedure - is there a tree or a
> hierarchy
> involved in these deletes?
> This could be optimized, take a look at this example:
> http://milambda.blogspot.com/2005/0...or-monkeys.html
> Deletes require exclusive locks - you should make the delete procedure as
> concise as possible - maybe even by building the list outside of a
> transaction, and only beginning an explicit transaction just before the
> actual delete statement. The delete will block other users anyway, so make
> it
> as short as possible.
>
> ML
> --
> http://milambda.blogspot.com/|||That certainly is one of the function's purposes - to get a list of all
descendants in a hierarchy.
ML
http://milambda.blogspot.com/|||Thanks for the link and suggestion. I'll try putting the select outside of
the transaction and get back to you on my results
Adrian
"ML" <ML@.discussions.microsoft.com> wrote in message
news:1DECC75A-38CD-40AB-BC63-50FD758231C9@.microsoft.com...
> Before I read through the entire procedure - is there a tree or a
> hierarchy
> involved in these deletes?
> This could be optimized, take a look at this example:
> http://milambda.blogspot.com/2005/0...or-monkeys.html
> Deletes require exclusive locks - you should make the delete procedure as
> concise as possible - maybe even by building the list outside of a
> transaction, and only beginning an explicit transaction just before the
> actual delete statement. The delete will block other users anyway, so make
> it
> as short as possible.
>
> ML
> --
> http://milambda.blogspot.com/
Wednesday, March 21, 2012
deadlock on parent-child relationship
commits then calls another program to insert rows to the child table.
This is causing a deadlock. When I looked at it, the
first program has an X lock on the primary key of the parent table and
the second program is trying to get a share lock on the index of the
parent table ?
Why is this happening ? How can I avoid it ?
Thanks
RogerMake sure the order of the tables in the from clause is the same in both
queries and consider using the UPDLOCK table hint.
Read more here:
http://msdn.microsoft.com/library/d... />
a_8i93.asp
http://msdn.microsoft.com/library/d... />
a_3hdf.asp
ML
http://milambda.blogspot.com/|||You can't avoid it unless both updates occur on the same connection, or
unless you bind the second connection to the first. Look up sp_bindsession
in BOL. Exclusive locks are held on an inserted row until it is committed,
so no other transaction can see the row until it's committed (unless you use
WITH(NOLOCK), which should be avoided whenever possible).
I prefer to dump an update that contains related information into temp
tables so that they can be committed using set-based operations within a
stored procedure, but that can have performance and scalability implications
depending on whether tempdb is on it's own disk subsystem and on whether
there's enough memory so that the contents of the temp tables aren't
migrated out to disk. Set-based operations minimize lock duration, index
maintenance and transaction logging, so it's a trade-off. Without testing,
it cannot be determined which method provides the best performance and
scalability for a particular update scenario. However, I prefer to keep
transaction processing within stored procedures because I've found that
troubleshooting and repairing blocking and deadlock problems is less
expensive if all transactions are contained in procedures. It's a lot
easier to add a SELECT WITH(UPDLOCK) to a stored procedure than to alter,
recompile, and redeploy a client program.
"Roger" <wonderinguys@.gmail.com> wrote in message
news:1138809010.484456.142920@.z14g2000cwz.googlegroups.com...
>I have a program that inserts a row to a parent table and before it
> commits then calls another program to insert rows to the child table.
> This is causing a deadlock. When I looked at it, the
> first program has an X lock on the primary key of the parent table and
> the second program is trying to get a share lock on the index of the
> parent table ?
> Why is this happening ? How can I avoid it ?
> Thanks
> Roger
>|||the program that inserts the child table is in a new spid...a different
one from the parent program. Why is that ? i am from DB2 running on
mainframe where this never happens. So need some help with this.|||On 2 Feb 2006 12:21:33 -0800, Roger wrote:
>the program that inserts the child table is in a new spid...a different
>one from the parent program. Why is that ? i am from DB2 running on
>mainframe where this never happens. So need some help with this.
Hi Roger,
That's the cause of your deadlock, then.
This surely doesn't happen automatically. In fact, you have to work
pretty hard to get a subprocedure to run in a different spid in SQL
Server. (Doing it from the client is easier, but still takes some
effort).
Can you post (snippets of) your code?
Hugo Kornelis, SQL Server MVP
deadlock on a single table but multiple processes
simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
Deadlock trace shows both spids are running exactly same statement within
the procedure. Depending upon input parameter the statement does either
insert or update. But the deadlock trace shows that deadlock happens when
both are running update statements. Multiple thread supposed to update same
table but different rows (at most couple of rows).
The object (key) they are deadlocking on is a non clustered index used to
search data for update. Update statement doesn't modify any column that
belongs to this non clustered index. Database is running on default
(read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
the stored procedrue, so I assume that the statement is not a part of
explicit transaction.
Questions:
1. Why sql server is using update lock (And not the shared lock) on the non
clustered index which used to search the data. The update statement doesn't
modify this non clustered index. In below statement Index id 5 is on
position_id, security_alias and long_short_indicator.
2. Why deadlock and not just blocking? What is a fix for this?
Below is the update_statement that both SPID are running:
UPDATE CA
SET CANCEL_STATUS = 'Y',
UPDATE_SOURCE = @.in_update_source,
UPDATE_DATE = GETDATE()
from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
WHERE POSITION_ID = @.nTargetPositionId
AND SECURITY_ALIAS = @.in_security_alias
AND LONG_SHORT_INDICATOR = 'L'
AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
AND STAR_TAG25 = @.in_event_id
AND CASH_BAL_INST = @.in_event_sequence
AND CANCEL_FLAG = 'N'
AND REFLEXIVE_FLOW = 'Y'
Below is output of deadlock trace:
Deadlock encountered ... Printing deadlock information
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Wait-for graph
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:1
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
CleanCnt:2 Mode: X Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 3::
2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
Ref:0 Life:02000000 SPID:589 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:470 ECID:0 Ec
0x72B99520) Value:0xb61fa660 Cost
0/7280)2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:2
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
CleanCnt:2 Mode: U Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 2::
2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
Ref:0 Life:00000001 SPID:470 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)Hi,
May I know why Index hint is used in update statement
(index(IND_CASH_ACT_SPD1))?
Manu
"James" wrote:
> Hi! We have a third party application that calls same stored procedure
> simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
> Deadlock trace shows both spids are running exactly same statement within
> the procedure. Depending upon input parameter the statement does either
> insert or update. But the deadlock trace shows that deadlock happens when
> both are running update statements. Multiple thread supposed to update same
> table but different rows (at most couple of rows).
> The object (key) they are deadlocking on is a non clustered index used to
> search data for update. Update statement doesn't modify any column that
> belongs to this non clustered index. Database is running on default
> (read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
> the stored procedrue, so I assume that the statement is not a part of
> explicit transaction.
> Questions:
> 1. Why sql server is using update lock (And not the shared lock) on the non
> clustered index which used to search the data. The update statement doesn't
> modify this non clustered index. In below statement Index id 5 is on
> position_id, security_alias and long_short_indicator.
> 2. Why deadlock and not just blocking? What is a fix for this?
> Below is the update_statement that both SPID are running:
> UPDATE CA
> SET CANCEL_STATUS = 'Y',
> UPDATE_SOURCE = @.in_update_source,
> UPDATE_DATE = GETDATE()
> from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
> WHERE POSITION_ID = @.nTargetPositionId
> AND SECURITY_ALIAS = @.in_security_alias
> AND LONG_SHORT_INDICATOR = 'L'
> AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
> AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
> AND STAR_TAG25 = @.in_event_id
> AND CASH_BAL_INST = @.in_event_sequence
> AND CANCEL_FLAG = 'N'
> AND REFLEXIVE_FLOW = 'Y'
> Below is output of deadlock trace:
> Deadlock encountered ... Printing deadlock information
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Wait-for graph
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:1
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
> CleanCnt:2 Mode: X Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 3::
> 2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
> Ref:0 Life:02000000 SPID:589 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:470 ECID:0 Ec
0x72B99520) Value:0xb61fa660 Cost
0/7280)> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:2
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
> CleanCnt:2 Mode: U Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 2::
> 2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
> Ref:0 Life:00000001 SPID:470 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)> 2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)>
>
deadlock on a single table but multiple processes
simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
Deadlock trace shows both spids are running exactly same statement within
the procedure. Depending upon input parameter the statement does either
insert or update. But the deadlock trace shows that deadlock happens when
both are running update statements. Multiple thread supposed to update same
table but different rows (at most couple of rows).
The object (key) they are deadlocking on is a non clustered index used to
search data for update. Update statement doesn't modify any column that
belongs to this non clustered index. Database is running on default
(read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
the stored procedrue, so I assume that the statement is not a part of
explicit transaction.
Questions:
1. Why sql server is using update lock (And not the shared lock) on the non
clustered index which used to search the data. The update statement doesn't
modify this non clustered index. In below statement Index id 5 is on
position_id, security_alias and long_short_indicator.
2. Why deadlock and not just blocking? What is a fix for this?
Below is the update_statement that both SPID are running:
UPDATE CA
SET CANCEL_STATUS = 'Y',
UPDATE_SOURCE = @.in_update_source,
UPDATE_DATE = GETDATE()
from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
WHERE POSITION_ID = @.nTargetPositionId
AND SECURITY_ALIAS = @.in_security_alias
AND LONG_SHORT_INDICATOR = 'L'
AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
AND STAR_TAG25 = @.in_event_id
AND CASH_BAL_INST = @.in_event_sequence
AND CANCEL_FLAG = 'N'
AND REFLEXIVE_FLOW = 'Y'
Below is output of deadlock trace:
Deadlock encountered ... Printing deadlock information
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Wait-for graph
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:1
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
CleanCnt:2 Mode: X Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 3::
2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
Ref:0 Life:02000000 SPID:589 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:470 ECID:0 Ec
0x72B99520) Value:0xb61fa660 Cost
0/7280)2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:2
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
CleanCnt:2 Mode: U Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 2::
2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
Ref:0 Life:00000001 SPID:470 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)Hi,May I know why Index hint is used in update statement
(index(IND_CASH_ACT_SPD1))?
Manu
"James" wrote:
> Hi! We have a third party application that calls same stored procedure
> simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
> Deadlock trace shows both spids are running exactly same statement within
> the procedure. Depending upon input parameter the statement does either
> insert or update. But the deadlock trace shows that deadlock happens when
> both are running update statements. Multiple thread supposed to update sam
e
> table but different rows (at most couple of rows).
> The object (key) they are deadlocking on is a non clustered index used to
> search data for update. Update statement doesn't modify any column that
> belongs to this non clustered index. Database is running on default
> (read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
> the stored procedrue, so I assume that the statement is not a part of
> explicit transaction.
> Questions:
> 1. Why sql server is using update lock (And not the shared lock) on the no
n
> clustered index which used to search the data. The update statement doesn'
t
> modify this non clustered index. In below statement Index id 5 is on
> position_id, security_alias and long_short_indicator.
> 2. Why deadlock and not just blocking? What is a fix for this?
> Below is the update_statement that both SPID are running:
> UPDATE CA
> SET CANCEL_STATUS = 'Y',
> UPDATE_SOURCE = @.in_update_source,
> UPDATE_DATE = GETDATE()
> from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
> WHERE POSITION_ID = @.nTargetPositionId
> AND SECURITY_ALIAS = @.in_security_alias
> AND LONG_SHORT_INDICATOR = 'L'
> AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
> AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
> AND STAR_TAG25 = @.in_event_id
> AND CASH_BAL_INST = @.in_event_sequence
> AND CANCEL_FLAG = 'N'
> AND REFLEXIVE_FLOW = 'Y'
> Below is output of deadlock trace:
> Deadlock encountered ... Printing deadlock information
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Wait-for graph
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:1
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
> CleanCnt:2 Mode: X Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 3::
> 2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x
0
> Ref:0 Life:02000000 SPID:589 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDA
TE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:470 ECID:0 Ec
0x72B99520) Value:0xb61fa660 Cost
0/7280)> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:2
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
> CleanCnt:2 Mode: U Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 2::
> 2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x
0
> Ref:0 Life:00000001 SPID:470 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDA
TE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)> 2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec
0x7445F520) Value:0x3dfb5460 Cost
0/1FA4)>
>sql
Saturday, February 25, 2012
DBSTATUS_UNAVAILABLE error
I have a pretty complex Data Flow that finishes with OLE DB Command. This calls a Stored Procedure with parameters (60-70 of them). The packgaes compiles OK and in run time, I get error below. When I go ahead and edit the field - remove it - save the package - add it back and re-run the package - it generates same error for a different field. When I re-assign all fields and re-run it again - it starts over to give me same error.
Help!
Error: 0xC0202009 at Load Divisions, Insert New Division Data record [82749]: An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E21 Description: "Invalid character value for cast specification".
Error: 0xC020901C at Load Divisions, Insert New Division Data record [82749]: There was an error with input column "exists_divid" (86315) on input "OLE DB Command Input" (82754). The column status returned was: "DBSTATUS_UNAVAILABLE".
Error: 0xC0209029 at Load Divisions, Insert New Division Data record [82749]: The "input "OLE DB Command Input" (82754)" failed because error code 0xC020906E occurred, and the error row disposition on "input "OLE DB Command Input" (82754)" specifies failure on error. An error occurred on the specified object of the specified component.
Error: 0xC0047022 at Load Divisions, DTS.Pipeline: The ProcessInput method on component "Insert New Division Data record" (82749) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread2" has exited with error code 0xC0209029.
Error: 0xC0047039 at Load Divisions, DTS.Pipeline: Thread "WorkThread1" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread1" has exited with error code 0xC0047039.
Error: 0xC0047039 at Load Divisions, DTS.Pipeline: Thread "WorkThread0" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread0" has exited with error code 0xC0047039.
heh...it works now. It was varchar source column and target INT column. The issue is it never errored this column - but told me about some other issue not even related.
Once I manually matched each field and fixed it - it started going through.
It's gotta be fixed...
|||Also - the same error message appears when your OLE DB command invalidates constraints - for example I experienced this error when I was trying to do UPDATE of a Column with a NULL value - and the column had not null constraint.Thanks Microsoft for such a "helpful" error message!
DBSTATUS_UNAVAILABLE error
I have a pretty complex Data Flow that finishes with OLE DB Command. This calls a Stored Procedure with parameters (60-70 of them). The packgaes compiles OK and in run time, I get error below. When I go ahead and edit the field - remove it - save the package - add it back and re-run the package - it generates same error for a different field. When I re-assign all fields and re-run it again - it starts over to give me same error.
Help!
Error: 0xC0202009 at Load Divisions, Insert New Division Data record [82749]: An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E21 Description: "Invalid character value for cast specification".
Error: 0xC020901C at Load Divisions, Insert New Division Data record [82749]: There was an error with input column "exists_divid" (86315) on input "OLE DB Command Input" (82754). The column status returned was: "DBSTATUS_UNAVAILABLE".
Error: 0xC0209029 at Load Divisions, Insert New Division Data record [82749]: The "input "OLE DB Command Input" (82754)" failed because error code 0xC020906E occurred, and the error row disposition on "input "OLE DB Command Input" (82754)" specifies failure on error. An error occurred on the specified object of the specified component.
Error: 0xC0047022 at Load Divisions, DTS.Pipeline: The ProcessInput method on component "Insert New Division Data record" (82749) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread2" has exited with error code 0xC0209029.
Error: 0xC0047039 at Load Divisions, DTS.Pipeline: Thread "WorkThread1" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread1" has exited with error code 0xC0047039.
Error: 0xC0047039 at Load Divisions, DTS.Pipeline: Thread "WorkThread0" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown.
Error: 0xC0047021 at Load Divisions, DTS.Pipeline: Thread "WorkThread0" has exited with error code 0xC0047039.
heh...it works now. It was varchar source column and target INT column. The issue is it never errored this column - but told me about some other issue not even related.
Once I manually matched each field and fixed it - it started going through.
It's gotta be fixed...
|||Also - the same error message appears when your OLE DB command invalidates constraints - for example I experienced this error when I was trying to do UPDATE of a Column with a NULL value - and the column had not null constraint.Thanks Microsoft for such a "helpful" error message!
Tuesday, February 14, 2012
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog
Hi. You have the wrong newsgroup, but one thing that would fix it
is to make the inner query with a different connection than the
outer query. An alternative would be to switch away from DbLib, so you
could do fetches in a cursor-based approach.
Joe Weinstein at BEA
Yog wrote:
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
> Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?
> Thanks in advance.
> Regards,
> Yog
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog
Yog,
You will need to either fetch all the values first, close the result set,
and then do your inner loop query logic or use two separate connections to
the same database. Just like the error message says, the problem is that you
have initiated an operation that still has data to be retrieved from the
server and then attempted to execute another query.
Jim
"Yog" <y.bang@.zensar.com> wrote in message
news:C638CAD8-C4E2-49DE-955B-BE0B34977DD2@.microsoft.com...
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to
communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the
result of a multiple-row based query in WHILE loop and execute another query
inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation
with results pending."
> Because of the tightly coupled business logic, its impossible to change
the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?
> Thanks in advance.
> Regards,
> Yog
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate
with the SQL Server2000 database.
There is typical scenario in the application where we want to process the re
sult of a multiple-row based query in WHILE loop and execute another query i
nside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with
results pending."
Because of the tightly coupled business logic, its impossible to change the
WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
YogYog,
Have you tried opening a second connection for the internal result set?
Russell Fields
"Yog" <y.bang@.zensar.com> wrote in message
news:0E65530E-C692-4850-8DF4-800912D22DBD@.microsoft.com...
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to
communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the
result of a multiple-row based query in WHILE loop and execute another query
inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation
with results pending."
> Because of the tightly coupled business logic, its impossible to change
the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?
> Thanks in advance.
> Regards,
> Yog|||You need to fetch all the rows to completion before issueing another query.
Ex do while .not eof()
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog
This is a problem which typically arises when the results from an ongoing
command are still being processed.
In your scenario, you have probably sent a command to the server before all
results from a previous command have been processed.
To overcome this problem, the only way is to wait for the results to
process from the first query and then start the new query in the same
session.
Please also review this very helpful link:
http://msdn.microsoft.com/library/de...us/dblibc/dbc_
pdc02_4sxl.asp
Hope this helps.
sanchans@.online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog
1. Create another connection and execute your "subquery" in that connection
2. Wait for Yukon release - it is announced that Yukon will support
simultaneous queries on the same connection
3. Use T-SQL procedure for doing such a processing instead of client-side
cursor emulation
"Yog" <y.bang@.zensar.com> wrote in message
news:E50F797E-9F9D-4487-ADAF-AD251F1DC620@.microsoft.com...
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to
communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the
result of a multiple-row based query in WHILE loop and execute another query
inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation
with results pending."
> Because of the tightly coupled business logic, its impossible to change
the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate
with the SQL Server2000 database.
There is typical scenario in the application where we want to process the re
sult of a multiple-row based query in WHILE loop and execute another query i
nside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with
results pending."
Because of the tightly coupled business logic, its impossible to change the
WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog1. Create another connection and execute your "subquery" in that connection
2. Wait for Yukon release - it is announced that Yukon will support
simultaneous queries on the same connection
3. Use T-SQL procedure for doing such a processing instead of client-side
cursor emulation
"Yog" <y.bang@.zensar.com> wrote in message
news:E50F797E-9F9D-4487-ADAF-AD251F1DC620@.microsoft.com...
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to
communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the
result of a multiple-row based query in WHILE loop and execute another query
inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation
with results pending."
> Because of the tightly coupled business logic, its impossible to change
the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?
DB-Library error 10038
We have VC++6.0 based application which uses DB-Library calls to communicate with the SQL Server2000 database.
There is typical scenario in the application where we want to process the result of a multiple-row based query in WHILE loop and execute another query inside WHILE loop based on the data in the result fetched.
The psuedo-code is as below
While (result.fetch())
{
//prepare where clause based on the data in the row fetched
char* strWhere= ...
//Execute the Query on the same connection using db-lib API
//Fetch the result
}
But DB-Library do not allow such scenario and throws below error
"DB-Library error 10038: Attempt to initiate a new SQL Server operation with results pending."
Because of the tightly coupled business logic, its impossible to change the WHILE LOOP and also the flow of the application.
Is there any solution for above said problem?
Thanks in advance.
Regards,
Yog1. Create another connection and execute your "subquery" in that connection
2. Wait for Yukon release - it is announced that Yukon will support
simultaneous queries on the same connection
3. Use T-SQL procedure for doing such a processing instead of client-side
cursor emulation
"Yog" <y.bang@.zensar.com> wrote in message
news:E50F797E-9F9D-4487-ADAF-AD251F1DC620@.microsoft.com...
> Hi There,
> We have VC++6.0 based application which uses DB-Library calls to
communicate with the SQL Server2000 database.
> There is typical scenario in the application where we want to process the
result of a multiple-row based query in WHILE loop and execute another query
inside WHILE loop based on the data in the result fetched.
> The psuedo-code is as below
> While (result.fetch())
> {
> //prepare where clause based on the data in the row fetched
> char* strWhere= ...
> //Execute the Query on the same connection using db-lib API
> //Fetch the result
> }
> But DB-Library do not allow such scenario and throws below error
> "DB-Library error 10038: Attempt to initiate a new SQL Server operation
with results pending."
> Because of the tightly coupled business logic, its impossible to change
the WHILE LOOP and also the flow of the application.
> Is there any solution for above said problem?