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

  • 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

  • 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.

    [font="Verdana"]--www.sqlvillage.com[/size][/font]

  • 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
  • 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. 🙂

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply