Solved

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

Posted on 2010-09-20
8
694 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now