Ms Sql Error Number 2601
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the sql server error code 2627 company Business Learn more about hiring developers or posting ads with us Stack Overflow
Sqlexception Number 2601
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 sql error 262 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Unique Key Violation in SQL Server - Is it safe to assume Error 2627? up vote 37 down vote error 2627 sql server 2008 favorite 3 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. } ? sql-server-2005 unique-constraint share|improve this question edited May 3 '12 at
Sql Error Code 2601
20:37 Mark Sowul 6,0042335 asked Jun 26 '11 at 11:47 User 1,25711932 add a comment| 3 Answers 3 active oldest votes up vote 73 down vote accepted 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 share|improve this answer answered Jun 26 '11 at 12:19 gbn 268k40379482 1 +1 for including the SQL –Peter H. Jul 3 '13 at 11:46 @gbn What is the difference between unique constraint and unique index? Don't both enforce indices? –student Feb 18 at 15:36 add a comment| up vote 4 down vote Here is a handy extension method I wrote to find these: public static bool IsUniqueKeyViolation(this SqlException ex) { return ex.Errors.Cast
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn sqlexception 2627 more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags error 2627 violation of primary key Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you,
Sql Server Error 547
helping each other. Join them; it only takes a minute: Sign up SqlException catch and handling up vote 42 down vote favorite 16 Q: Is there a better way to handle SqlExceptions? The below examples rely on interpreting http://stackoverflow.com/questions/6483699/unique-key-violation-in-sql-server-is-it-safe-to-assume-error-2627 the text in the message. Eg1: I have an existing try catch to handle if a table does not exist. Ignore the fact that I could check if the table exists in the first place. try { //code } catch(SqlException sqlEx) { if (sqlEx.Message.StartsWith("Invalid object name")) { //code } else throw; } Eg2: without the try catch showing duplicate key exception if (sqlEx.Message.StartsWith("Cannot insert duplicate key row in object")) Solution: The start of my SqlExceptionHelper //-- http://stackoverflow.com/questions/6221951/sqlexception-catch-and-handling to see list of error messages: select * from sys.messages where language_id = 1033 order by message_id public static class SqlExceptionHelper { //-- rule: Add error messages in numeric order and prefix the number above the method //-- 208: Invalid object name '%.*ls'. public static bool IsInvalidObjectName(SqlException sex) { return (sex.Number == 208); } //-- 2601: Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls. public static bool IsDuplicateKey(SqlException sex) { return (sex.Number == 2601); } } c# exception-handling sqlexception share|improve this question edited May 31 '13 at 23:37 asked Jun 3 '11 at 0:54 Valamas - AUS 11.6k1873126 add a comment| 8 Answers 8 active oldest votes up vote 80 down vote accepted The SqlException has a Number property that you can check. For duplicate error the number is 2601. catch (SqlException e) { switch (e.Number) { case 2601: // Do something. break; default: throw; } } To get a list of all SQL errors from you server, try this: SELECT * FROM sysmessages Update This can now be simplified in C# 6.0 catch (SqlException e) when (e.Number == 2601) { // Do something. } share|improve this answer edited Aug 30 at 23:50 answered Jun 3 '11 at 1:04 Richard Schneider 23.7k53453 1 And you can filter by the language: select * from sysmessages
Messages 2001-3000 Messages 3001-4000 Messages 4001-5000 Messages 5001-6000 Messages 6001-7000 Messages 7001-7500 Messages 7501-8000 Messages 8001-8500 Messages 8501-9000 Messages http://www.sql-server-helper.com/error-messages/msg-2601.aspx 9001-9500 Messages 9501-10000 Messages 10001-10500 Messages 10501-11000 Messages 11001-11500 Messages 11501-12000 http://gursethi.blogspot.com/2010/08/error-2601-severity-14-state-1-cannot.html Messages 12001-13000 Messages 13001-13500 Messages 14001-14500 Home>SQL Server Error Messages> Msg 2601 - Cannot insert duplicate key row in object '
Hi Team, Here by I would like to share a problem which I faced in once of my account, Environment **************** SQL Server 2008 Enterprise Edition x64 10.00.2531 (Service Pack 1) Windows 2003 Enterprise Edition x64 SP2 Problem Description ************************* * We have CHANGE TRACKING enabled on one of our database. * Because of some problem we restarted SQL Server Services and after that we start getting below error messages: 2010-03-30 09:47:57.42 spid13s Error: 2601, Severity: 14, State: 1. 2010-03-30 09:47:57.42 spid13s Cannot insert duplicate key row in object 'sys.syscommittab' with unique index 'si_xdes_id'. 2010-03-30 09:47:57.42 spid13s Error: 3999, Severity: 17, State: 1. 2010-03-30 09:47:57.42 spid13s Failed to flush the commit table to disk in dbid 6 due to error 2601. Check the errorlog for more information. * Manual CHECKPOINT operation & Backup of database also got failed with the same error. Resolution As Per KB Article ***************************** * Microsoft Identified this problem as a bug and as per resolution one need to apply SQL Server 2008 Service Pack 1 Cummulative Update 7. * Below is the KB artcile. A backup Operation On A SQL Server 2008 Database Fails If You Enable Change Tracking On This Database http://support.microsoft.com/kb/978839 Twist In The Tail ***************** * This KB has a WORK AROUND section which talk about: Restarting SQL Server Services Disable Change Tracking Re-enable Change Tracking * We did worked as per this method (below) but it didn't resolved our problem : Restart SQL Server Services. Disable Change Tracking On All The Tables Involved. Disable Change Tracking at Database Level. Re-enabled Change Tracking at Database Level, Re-enabled Change Tracking on All the Tables Involved. * We applied Cummulative Update 7 of Service Pack 1 of SQL Server 2008 but still problem persists. * The reason was that still somehow some system was trying to insert Duplicate Values in table "SYS.SYSCOMMITTAB". * We checked with Microsoft and came to know that we have to first delete DUPLICATE rows from this "SYS.SYSCOMMITTAB" table. * We put