Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sqlstate 5001 error "There is already an object named PKCURSOR in the database" Expand / Collapse
Author
Message
Posted Thursday, March 20, 2008 2:04 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 5, 2009 11:25 AM
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
Post #472545
Posted Thursday, March 20, 2008 2:56 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 3, 2013 4:44 PM
Points: 1,336, Visits: 595
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
Post #472578
Posted Friday, March 21, 2008 3:03 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:19 AM
Points: 40,208, Visits: 36,617
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 2008, MVP
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

Post #473121
Posted Tuesday, March 25, 2008 7:00 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 5, 2009 11:25 AM
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.
Post #474020
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse