?
Solved

Negative "Primary Keys" show up when openning an SQL Server 2008 database in a Visual basic program.

Posted on 2010-09-20
8
Medium Priority
?
713 Views
Last Modified: 2013-11-26
Why am I getting Negative primary Keys?  The primary key field is set with Identity Spec (Yes). Is Identity (Yes). Identity increment (3), not -3. Identity seed 866731. I am using a data Grid from the table set.  
0
Comment
Question by:jampost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720725
you see identity while you adding new data?or after update?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720726
i mean negative identity...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720755
It could happen..and it is logic...http://blog.sqlauthority.com/2010/08/19/sql-server-negative-identity-seed-value-and-negative-increment-interval/
"Negative identity values are useful in programming: if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment). Therefore it is common to use negative identities and increments for the memory dataset and positive ones for the server database. The server does understands that mechanism and will assign correct values (It will take some tricks to refresh these values into the memeory dataset)."
For a more elaborate artikel see: Managing an @@Identity crisis at http://msdn.microsoft.com/en-us/library/ms971502.aspx
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:jampost
ID: 33721540
jtoutou,
    Thank you for your quick responce. The negative PKs are there before I enter the first record in the dataset. The database & table were all created in the SQL Server Management Studio. The data will be entered through a visual basic program, and that is were the negatives are showing up. I have to admit; I am not a level two or above programer. I assume you are telling me that this is normal. The problem I have is that this is a GUI. There would be no problem if this were behind the scenes. So I guess I need some specificities to correct this.
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 2000 total points
ID: 33722162
As far as i know You do not have to correct anything..."if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment)"
0
 

Author Comment

by:jampost
ID: 33730426
Jtoutou,
       
          Thank you. I probably need to get acquainted with the world of SQL. This is what I found out. First off you were very helpful in what you told me. I test by clearing all records and starting fresh. Going through the Data Set (The program I am developing in Visual Basic) Row one “Primary Key (“Customer Number” field heading),  I get -1 as the primary key. But…….When I open SQL Server 2008 and check the results in the table it has the test seed I planted (866731).  Now here is the head scratcher (to me anyway). I go back into Visual Studio and Start Debugging (running) the program and (NOW) it has 866731 in place of -1. I suppose it just needed to get refreshed.  Thank you, and I hope you will see my future questions. You have an A grade and 500 points.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33731798
hi....
very glad i helped you...


P.S You have to accept a solution if you got your answer...:)

0
 

Author Comment

by:jampost
ID: 33735428
I thought I accepted the solution yesterday. It is sort of like the debit card machine at check out. You start to walk away and it has one more yes box to click.  I think I got it this time. Thanks again
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question