Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 376205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:34:35+00:00 2026-05-12T14:34:35+00:00

I am developing an Windows pplication(using Visual Studio 2008,Sql server 2005). I have to

  • 0

I am developing an Windows pplication(using Visual Studio 2008,Sql server 2005). I have to maintain userlog information. I am having an identity column. It is working fine. But now the value of identity column is 172. Again when I try to log on I am getting the error as:

Violation of Primarykey pk_userLogId cannot insert duplicate values in an object’dbo.UserLog’.
The statement has been terminated.

When I close the error dialog box I am able to still use the application but the userlog is not being maintained.

What should I do to avoid getting this error message?

Is there any way I could set the maximum value for an identity column?

please help me out!
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:34:36+00:00Added an answer on May 12, 2026 at 2:34 pm

    My initial response was wrong because it was based on a misunderstanding about the log table schema. In view of Sheetal’s later posting of this schema (and my realizing that the name of the column was UserLogId, not UserLoginID…) this hypothesis is invalidated.

    The log table is therefore,

    CREATE TABLE USERLOG 
    ( UserLogId int identity (1,1) CONSTRAINT pk_UserLogId primary key, 
      UserName nvarchar(50) not null, 
      LogInTime datetime CONSTRAINT dft_LogInTime default getdate() 
    ) 
    --ADDING LOGOUT TIME ALTER TABLE USERLOG ADD LogOutTime datetime
    

    making the OP question the more puzzling…

    How can one get PK violation conditions with an identity column?
    (unless the INDENTITY_INSERT setting for that table, and that manual edits/insert that include a value for the PK column, maybe Sheetal can shed some light on that… ? )

    Sheetal should therefore look into the application’s logic, in the area of the code that completes the login, after the user is authenticated, and look for instance of queries where a value is specified for the UserLogId column (other than in WHERE clauses, of course).

    — the following is wrong (based on wrong hypothesis) —-

    The issue seems to be that the UserLoginId is declared as the Primary Key for the log table. This is a odd choice for such a table because we’d expect to have many log records for a given user.

    In a SQL table, the primary key constraint essentially instructs SQL to refuse any INSERT request for a records with a Primary Key value that readily exist in the table. (And to return an error condition similar to the one mentioned in the question)

    It’s hard to advise not knowing the log table schema and use case, but you can maybe remove the pk constraint altogether or use another column for it. An auto-incremented column called "EventId" could be a good choice for it. You’d get something like that in the log table:

    EventID (PK)   DateTime              UserLoginId  EventType     Details
    1              01/02/2008 06:15:01   172          LogIn         Stan
    2              01/02/2008 06:15:21   321          LogIn         Jeff
    3              01/02/2008 06:15:24   172          FileDownload  Report7.pdf
    4              01/02/2008 06:15:54   172          FileDownload  SalesTraining.pdf
    5              01/02/2008 06:17:21   321          LogOut        
    

    etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can set file encoding for tomcat in CATALINA_OPTS environment… May 12, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer Regardless of any other books, you will definitely need ECMA-335… May 12, 2026 at 9:25 pm
  • Editorial Team
    Editorial Team added an answer I went with this in the end: Service used to… May 12, 2026 at 9:25 pm

Related Questions

I am developing a Windows Application using the .net Framework 2.0 and Visual C#(Microsoft
I am developing an Isolated Shell that caters to designers/special content creators performing specific
For years Windows XP (32 bit)was my development desktop (personal projects). I develop many
I am preparing for the development of an enterprise-style application for a very small
I developing ASP.NET application using a Swedish version of Windows XP and Visual studio

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.