Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Erratic behaviour of a stored procedure

Author  Topic 

Parkaw
Starting Member

16 Posts

Posted - 2006-07-19 : 16:05:33
Just having a few problems with a SP.

CREATE PROCEDURE dbo.GMWBWImportScript AS

declare @gmnv varchar(20)
declare @recid varchar(15)
declare @ACCOUNTNO varchar(20)
declare @itemcode varchar(35)
declare @INFO varchar(255)
declare @Desc1 varchar(20)
declare @invoicedate varchar(10)
declare @supplierID varchar(20)
declare @unitPrice varchar(10)
declare @Shipqty varchar(6)
declare @totalsaleamt varchar(20)
declare @invoicelineuid varchar(40)
declare @desc2 varchar(40)
declare @city varchar(30)
set nocount on

DECLARE bclwbw2 CURSOR
FOR select accountno, invoice_line_uid, item_id, INFO, [Item Desc], invoice_date, supplier_name, unit_price, qty_shipped, extended_price, [desc 2], city from bclgmItemDetailImport

OPEN bclwbw2

FETCH NEXT FROM bclwbw2 INTO @ACCOUNTNO, @invoicelineuid, @itemcode , @INFO, @Desc1, @invoicedate, @supplierID, @unitprice, @Shipqty, @totalsaleamt, @desc2, @city

WHILE @@fetch_status = 0
begin

EXEC GMW_NV_Create @gmnv OUTPUT
EXEC GMW_NV_SetValue @gmnv, 'user', 'MASTER'
EXEC GMW_NV_SetValue @gmnv, 'AccountNo', @ACCOUNTNO
EXEC GMW_NV_SetValue @gmnv, 'detail', 'Item Sold'
EXEC GMW_NV_SetValue @gmnv, 'ref', @itemcode
EXEC GMW_NV_SetValue @gmnv, 'notes', @INFO
EXEC GMW_NV_SetValue @gmnv, 'ufield1', @Desc1
EXEC GMW_NV_SetValue @gmnv, 'ufield2', @invoicedate
EXEC GMW_NV_SetValue @gmnv, 'ufield3', @supplierID
EXEC GMW_NV_SetValue @gmnv, 'ufield4', @unitPrice
EXEC GMW_NV_SetValue @gmnv, 'ufield5', @Shipqty
EXEC GMW_NV_SetValue @gmnv, 'ufield6', @totalsaleamt
EXEC GMW_NV_SetValue @gmnv, 'ufield7', @invoicelineuid
EXEC GMW_NV_SetValue @gmnv, 'ufield8', @desc2
EXEC GMW_NV_SetValue @gmnv, 'ufield9', @city
EXEC GMW_WriteDetail1 @gmnv
EXEC GMW_NV_GetValue @gmnv, 'recid', @recid OUTPUT

FETCH NEXT FROM bclwbw2 INTO @ACCOUNTNO, @invoicelineuid, @itemcode , @INFO, @Desc1, @invoicedate, @supplierID, @unitprice, @Shipqty, @totalsaleamt, @desc2, @city
end

DEALLOCATE bclwbw2

EXEC GMW_NV_Delete @gmnv
GO


It works without errors every OTHER day, but returns errors on the other days.

Errors such as :

7/18/06
Transaction (Process ID 65) was deadlocked on {lock} resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001] (Error 1205).  The step failed.

7/16/06
Line 1: Incorrect syntax near 'DO'. [SQLSTATE 42000] (Error 170)  Associated statement is not prepared [SQLSTATE HY007] (Error 0).  The step failed.

7/14/06
Line 1: Incorrect syntax near 'DO'. [SQLSTATE 42000] (Error 170)  Associated statement is not prepared [SQLSTATE HY007] (Error 0)  Line 1: Incorrect syntax near 'DO'. [SQLSTATE 42000] (Error 170).  The step failed.

7/12/06
Line 1: Incorrect syntax near 'DO'. [SQLSTATE 42000] (Error 170)  Associated statement is not prepared [SQLSTATE HY007] (Error 0)  Transaction (Process ID 70) was deadlocked on {lock} resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001] (Error 1205).  The step failed.


As you can see, it has returned a myriad of different errors. The incorrect syntax near 'DO' bothers me, primarily because I didn't use a do loop. Nor are there any DO loops in the called stored procedures.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-19 : 16:58:32
In order to resolve deadlocks, you'll have to analyze the code inside the stored procedures and compare them to the other set of code that is involved in the deadlock. There is no way for us to resolve the deadlocks with just the code from this one stored procedure.

Are these errors from a job?

You need to read up on deadlocks in SQL Server Books Online. It'll show you how to figure out what the query is that is involved in the deadlock.


Tara Kizer
Go to Top of Page

Parkaw
Starting Member

16 Posts

Posted - 2006-07-19 : 17:33:43
I'm reasonably familiar with deadlocks, and am working on troubleshoot that part of it. Currently working on setting up the profiler to track just this job.
And yes, all 4 of those errors were from that stored procedure on different days.
Between each of those errors it ran without any errors for a day.
I'm a bit more concerned with the errors concerning the invalid syntax near 'DO'. I've looked over every bit of code involved with this and there aren't any 'DO' loops.
So far the method seems to be working, but those errors confused me.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-19 : 17:37:07
What is executing this stored procedure?

The DO errors aren't coming from the stored procedure. Add Exception event to your trace. I seriously doubt you'll ever capture a do error in regards to this stored procedure when the error is encountered from the app (whatever the app is).

Tara Kizer
Go to Top of Page

Parkaw
Starting Member

16 Posts

Posted - 2006-07-19 : 17:40:19
I setup a job in sql server agent using enterprise manager.
'EXEC GMWBWImportScript'
is the only code in it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-19 : 17:42:10
That is very fishy. What version of SQL Server are you using? SELECT @@VERSION

Did you search the 4 stored procedures for the word DO? Any instances of it?

Tara Kizer
Go to Top of Page

Parkaw
Starting Member

16 Posts

Posted - 2006-07-19 : 17:46:08
Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 6 2000 00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

I did check the 4 stored procedures for the word 'DO' and did not find any instance of it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-19 : 17:48:35
8.00.194 means you don't have any service packs applied. SQL Server 2000 is up to service pack 4, although I'd recommend sp3a with security patch 818 instead.

Since the word DO doesn't appear in any of your code, I'd install either sp3a + security patch 818 or sp4. It could be a bug. I've never even touched SQL Server 2000 without a service pack.

Tara Kizer
Go to Top of Page
   

- Advertisement -