Ошибка sql state 23000 native 2627

  • Remove From My Forums
  • Question

  • hello,
    I noticed I have some of those erros on my  PS_DBagaent_system_log

    2009-08-25 21:54:58 err=-1, [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint ‘PK_GuildChars’. Cannot insert duplicate key in object ‘dbo.GuildChars’., SQL STATE: 23000, NATIVE ERROR: 2627 (0xA43)

    2009-08-25 21:54:58 DBGuild::CreateChatacter Failed 211, qerr=-1, EXEC usp_Create_GuildChar_E 6, 211, 0

    2009-08-26 02:03:21 err=-1, [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint ‘PK_CharApplySkills’. Cannot insert duplicate key in object ‘dbo.CharApplySkills’., SQL STATE: 23000, NATIVE ERROR: 2627 (0xA43)

    2009-08-26 02:03:21 ::SaveCharacter 478 Wind ret=-1, qerr=-1, {?=call Usp_Save_Char_ApplySkill_Add_E(478,30,3,300)}

    2009-08-26 14:33:26 err=-1, [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint ‘PK_CharSavePoint’. Cannot insert duplicate key in object ‘dbo.CharSavePoint’., SQL STATE: 23000, NATIVE ERROR: 2627 (0xA43)

    2009-08-26 14:33:26 InsertSavePoint qerr=-1, EXEC usp_Create_Char_SavePoint 1686,1,2,843.802917,39.217873,1771.947388

    2009-08-26 14:33:26 ::SaveCharacter 1686 [GS]Kira ret=1, qerr=-1, EXEC usp_Create_Char_SavePoint 1686,1,2,843.802917,39.217873,1771.947388

    im running a online Game with SQL 2005 enterprise, I hope someone can tell me how fix it, I already fix a big problem with the help of Jhonatan here :D now this website is my idol :D

    thanks

Answers

  • Looks like the table is designed in such a way that the field must have only unique values. The answer to your question depends on where is the duplicate coming from. Is the key an identity field? Is it being generated in the SP or it’s being passed as a parameter? We want to understand what part of your code is generating the unique values so we need more details.

    Thanks,


    Varsham Papikian, New England SQL Server User Group Executive Board, USA

    New England SQL Server User Group;
    My LinkedIn page

    Please remember to click the «Mark as Answer» button if a post helps you!

    • Marked as answer by

      Thursday, August 27, 2009 9:03 AM

  • Hi Hetan,
    There are some Primary Key issues in this 2 tables…

    1) ‘dbo.CharApplySkills’
    2) ‘dbo.CharSavePoint’

    I think there may be 2 solutions :

    1st : Identifying how duplicate data is coming to both the tables. Ideally it should not come.
    2nd : If not identified… Try removing : the primary key constraint.

    1st solution is recommended.

    Please Vote & «Mark As Answer» if this post is helpful to you.

    Cheers
    Bikash Dash


    MCDBA/MCITP

    • Edited by
      Bikash Dash
      Thursday, August 27, 2009 5:38 AM
    • Marked as answer by
      Hetan
      Thursday, August 27, 2009 9:03 AM

  • Please give us the table structure of 2 tables.

    1) ‘dbo.CharApplySkills’
    2) ‘dbo.CharSavePoint’

    Please Vote & «Mark As Answer» if this post is helpful to you.

    Cheers
    Bikash Dash

    MCDBA/MCITP

    • Marked as answer by
      Hetan
      Thursday, August 27, 2009 9:03 AM

  • I checked the package and I see that it doesn’t have the code piece we need.

    Right click on the database, choose Tasks and then Generate Scripts. Follow the wizard. Just script the whole database (tables, indexes, SPs…).

    Then post the code.

    Thanks,


    Varsham Papikian, New England SQL Server User Group Executive Board, USA

    New England SQL Server User Group;
    My LinkedIn page

    Please remember to click the «Mark as Answer» button if a post helps you!

    • Marked as answer by
      Hetan
      Thursday, August 27, 2009 8:33 PM

  • I did some troubleshooting. Here is the result:

    I see three errors: in all cases you have a primary key defined for a table (single column one or a multiple column one) and your Stored Procedures try to insert duplicate rows.
    The values for the keys are NOT generated inside your Stored Procedures so the SPs are not responsible for the error. 

    Resolution:  you have to check the code (app code?) which is specifying the input parameters for the SPs and check the logic there. I am assuming that the Primary Keys are defined ‘right’ and the column/s values in the PK have to be unique for the application to work properly. How is the application making sure that it doesn’t specify ‘bad’ input param values when calling the SPs?

    Your application could catch this specific type of error (dup values) and do something with it. Or you could do some extra checking in the SPs.
    You could do other improvements too: for example ISNULL in ISNULL(count(*), 0) is redundant since the result of count(*) is never NULL (even if there is no qualifying row).

    More details:

    1.
    SP used: usp_Create_GuildChar_E
    Updates the table: GuildChars
    Primary key [PK_GuildChars] on [GuildID],[CharID]
    Call: usp_Create_GuildChar_E 6, 211, 0
    Fail reason: a row where [GuildID]=6  and [CharID]=211 already exists so INSERT conflicts with Primary key [PK_GuildChars].

    2.
    SP used: usp_Save_Char_ApplySkill_Add_E
    Updates the table: CharApplySkills
    Primary key [PK_CharApplySkills] on [CharID],[SkillID]
    Call: Usp_Save_Char_ApplySkill_Add_E 478,30,3,300
    Fail reason: a row where [CharID]=478 and [SkillID]=30 already exists so INSERT conflicts with Primary key [PK_CharApplySkills].

    3.
    SP used: [usp_Create_Char_SavePoint]
    Updates the table: CharSavePoint
    Primary key [PK_CharSavePoint] on [CharID]
    Call: usp_Create_Char_SavePoint 1686,1,2,843.802917,39.217873,1771.947388
    Fail reason: a row where [CharID]=1686 already exists so INSERT conflicts with Primary key [PK_CharSavePoint].

    Hope this was useful for you and you can identify the core issue and improve the application.

    Thanks,


    Varsham Papikian, New England SQL Server User Group Executive Board, USA

    New England SQL Server User Group;
    My LinkedIn page

    Please remember to click the «Mark as Answer» button if a post helps you!

    • Marked as answer by
      Hetan
      Friday, August 28, 2009 10:13 AM

  • Did the application work before as a whole or you are just starting to develop it? If we assume that the back-end design is ‘right’ then you need to check the module which calls the SPs and make sure it doesn’t pass values which conflict with the primary keys. 

    As you see, the answers are starting to depend on many internal details in your application. Not that I don’t want to continue, but you need to formalize the questions a little bit better so that we have enough info for answering without going into the application details :-)

    Thanks,


    Varsham Papikian, New England SQL Server User Group Executive Board, USA

    New England SQL Server User Group;
    My LinkedIn page

    Please remember to click the «Mark as Answer» button if a post helps you!

    • Marked as answer by
      Hetan
      Friday, August 28, 2009 9:33 PM

to continue to Google Sites

Not your computer? Use Guest mode to sign in privately. Learn more

Я
   Arcana

24.07.08 — 14:45

Иногда при проведении выписки (исключительно этого вида документа)возникает ошибка: SQL State:23000 Native:2627 Message: [Microsoft][ODBC SQL Server Driver][SQL Server] Violation of PRIMARY KEY constraint ‘PK_DT238’. Cannot insert duplicate key in object ‘dbo.DT238’. По всей видимости происходит сбой значения счетчика. После того как документ снова открыли, он записался нормально. Подскажите, как избежать повторения такой ситуации?

   ТелепатБот

1 — 24.07.08 — 14:45

Книга знаний: Множественный отбор в журналах и справочниках 7.7 заменой запросов SQL

   Arcana

2 — 24.07.08 — 17:00

up

   lea_220400

3 — 24.07.08 — 17:02

‘dbo.DT238’ — это есть таблица SQL для документа.

   lea_220400

4 — 24.07.08 — 17:03

вернее dbo — это обращение к таблице этой. короче не может вставить дубликат ключа в объект, т.к. он тама есть.

Как версии ТИИ.

   lift

5 — 25.07.08 — 10:09

(0) да в этой табличке дела плоховатые. Для начала ТИИ, далее тестирование средствами SQL

   Кириллка

6 — 25.07.08 — 10:20

(4)»вернее dbo — это обращение к таблице этой.» — что сие означает? Только по-русски, как для военных, плиз.

   Arcana

7 — 25.07.08 — 10:28

Тестирование и исправление не делали, все заработало. Вопрос заключается в том, как избежать повторения такой ситуации?

  

Arcana

8 — 28.07.08 — 12:25

up

TurboConf — расширение возможностей Конфигуратора 1С

I have this SQL Server agent job that runs on a daily basis that calls & execute 2 stored procedures. The issue is that the job fails, but not on a daily basis. The last job execution failure was on 8th March 2016. Then the job succeeded on 9th March 2016. Today (10th March 2016), the job failed again.

Here is the error message:

Executed as user: DB2-AYOPAYdb_service. Violation of UNIQUE KEY
constraint ‘IX_SnapShot’. Cannot insert duplicate key in object
‘dbo.SnapShot’. The duplicate key value is (2, 1, 1, 10, 3, 2016).
[SQLSTATE 23000] (Error 2627) Mail (Id: 1079) queued. [SQLSTATE
01000] (Error 0) The statement has been terminated. [SQLSTATE 01000]
(Error 3621) Ayopay Indonesia Reload 09
Mar 2016

TOTAL RELOADIDR
39,982,651.00RM
11,407.84TOTAL NEW USER16

 SUCCESSINCOMPLETECHANNELQTYIDRRMQTYIDRRMOFFLINE RELOADBCA3720,373,800.005,813.05112,591,000.00739.26BRI156,730,000.001,920.20216,300,000.001,797.52Mandiri186,878,851.001,962.67124,818,850.001,374.91TOTAL7033,982,651.009,695.924413,709,850.003,911.69 ONLINE RELOADFinnet —
ATM75,000,000.001,426.60

I would appreciate if someone could guide/lead me into the right direction. I have no prior experience in handling error messages such as this. I know that there were similar error messages posted b4, but i still could not wrap my head around it, due to my inexperience.

The server is running on

Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

My 1st attempt is to look for the object name ‘dbo.SnapShot’, but to no avail. Any help is much appreciated. TQ

I need to catch violation of UNIQUE constraints in a special way by a C# application I am developing. Is it safe to assume that Error 2627 will always correspond to a violation of this kind, so that I can use

if (ThisSqlException.Number == 2627)
{
    // Handle unique constraint violation.
}
else
{
    // Handle the remaing errors.
}

?

Mark Sowul's user avatar

Mark Sowul

10.2k1 gold badge44 silver badges51 bronze badges

asked Jun 26, 2011 at 11:47

User's user avatar

2627 is unique constraint (includes primary key), 2601 is unique index

SELECT * FROM sys.messages
WHERE text like '%duplicate%' and text like '%key%' and language_id = 1033

answered Jun 26, 2011 at 12:19

gbn's user avatar

gbngbn

421k81 gold badges585 silver badges674 bronze badges

4

Here is a handy extension method I wrote to find these:

    public static bool IsUniqueKeyViolation(this SqlException ex)
    {
        return ex.Errors.Cast<SqlError>().Any(e => e.Class == 14 && (e.Number == 2601 || e.Number == 2627 ));
    }

answered Dec 18, 2015 at 18:41

jhilden's user avatar

jhildenjhilden

12.1k5 gold badges52 silver badges76 bronze badges

1

Within an approximation, yes.

If you search the MS error and events site for SQL Server, error 2627, you should hopefully reach this page1, which indicates that the message will always concern a duplicate key violation (note which parts are parameterized, and which not):

Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'.

1As @2020-06-18, Database engine errors and events would be the correct page to go to

answered Jun 26, 2011 at 11:52

Damien_The_Unbeliever's user avatar

3

Понравилась статья? Поделить с друзьями:
  • Ошибка spn 3226 fmi 15 камаз cummins
  • Ошибка sql server права доступа
  • Ошибка sql server не существует или доступ запрещен
  • Ошибка sql server interfaces error 26
  • Ошибка spn 2003 fmi 31