Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sqlstate 5001 error "There is already an object named PKCURSOR in the database"


sqlstate 5001 error "There is already an object named PKCURSOR in the database"

Author
Message
Keith Knox
Keith Knox
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 149
We have Powerbuilder app that ran fine on the 2000 db before we migrated to 2005.
Now we get the following error:
sqlstate 5001 error "There is already an object named PKCURSOR in the database"

The partial code below has been modified by adding a drop contraint PKCURSOR . So the error does not pop up now for 2 of the dba's who have powerbuilder installed and they run the app from their network drive. The other user runs it from her network drive and gets the error. I've also made that user a dbo and still gets the error.
Any ideas?

ALTER PROCEDURE [dbo].[GUMBO_SP_PROP_ACTUAL_ACCOMPLISHMENTS_PF] @PROG_YEAR CHAR(4) AS

DECLARE @PROGRAM_YEAR CHAR(4),
@SUM_LOW_MOD_PERSONS_PROPOSED INTEGER,
@SUM_LOW_MOD_PERSONS_ACTUAL INTEGER,
@SUM_TOTAL_PERSONS_PROPOSED INTEGER,
@SUM_TOTAL_PERSONS_ACTUAL INTEGER,
@ERROR_STRING CHAR(132) ,
@ACTIVITY_CODE CHAR(3)

CREATE TABLE #ACCOMPLISHMENTS
(PROGRAM_YEAR CHAR(4) NOT NULL,
ACTIVITY_CODE CHAR(3) NOT NULL,
TOTAL_PERSONS_PROPOSED DECIMAL(18,2) DEFAULT 0,
TOTAL_PERSONS_ACTUAL DECIMAL(18,2) DEFAULT 0,
LOW_MOD_PERSONS_PROPOSED DECIMAL(18,2) DEFAULT 0,
LOW_MOD_PERSONS_ACTUAL DECIMAL(18,2) DEFAULT 0)

-- Alter the temporary table to have a primary key of application number and program year.

ALTER TABLE #ACCOMPLISHMENTS
ADD CONSTRAINT PKCURSOR PRIMARY KEY (PROGRAM_YEAR, ACTIVITY_CODE)
DECLARE ACTIVITY_CURSOR CURSOR FOR
SELECT dbo.ACTIVITY_CODE.activity_code
FROM dbo.ACTIVITY_CODE
WHERE (dbo.ACTIVITY_CODE.activity_code LIKE 'P%%') and (dbo.ACTIVITY_CODE.activity_code <> 'P01')
ORDER BY dbo.ACTIVITY_CODE.activity_code
ALTER TABLE #ACCOMPLISHMENTS
DROP CONSTRAINT PKCURSOR
Mohan Kumar
Mohan  Kumar
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1341 Visits: 596
execute select * from sysindexes where name ='PKCURSOR' to see whether you have PKCURSOR already in your database or not. Please do this before you try to run script mentioned. If it returns you row that means you need to change constraint name to something else.

--www.sqlvillage.com
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47376 Visits: 44399
ALTER TABLE #ACCOMPLISHMENTS
ADD CONSTRAINT PKCURSOR PRIMARY KEY (PROGRAM_YEAR, ACTIVITY_CODE)


When you create a temp table, SQL server hashes the name so that there's no name collision. TempDB has the same rules as all other databases - no 2 objects have the same name.

If 2 connections both create a temp table with the name #tmpTable, they'll appear in the tempDB system tables looking something like this

#tmpTable_____________________________________73921
#tmpTable_____________________________________05482

When you do al alter table add constraint and explicitly set the name, SQL doesn't do that kind of hashing. Hence if two connections are running that proc, the first will run fine, the second will try to create a constrain with the same name as an existing one, and will fail.

What I would recommend you do is create a unique index, rather than a primary key. Index names are only unique at the table level.


CREATE UNIQUE INDEX idx_pkCursor ON #ACCOMPLISHMENTS
(PROGRAM_YEAR, ACTIVITY_CODE)




Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Keith Knox
Keith Knox
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 149
thanks for the help.
For now, the drop contraint is working. There were 2 other sp's that needed the drop contraint modification.

thanks

I passed that coding info on to our developers. :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search