all groups > sql server programming > november 2006 >
You're in the

sql server programming

group:

Missing records in database...


Missing records in database... hurricane_number_one NO[at]SPAM yahoo.com
11/18/2006 6:15:27 PM
sql server programming:
One table in my database keeps dropping or never storing some records.
When I look at the auto-incrementing IDs there is a missing ID here and
there. There is nothing in my software that can delete a record from
this table so it must have never been stored to begin with, but it is
using up an ID. There is a 2nd table that gets written to also when
this one gets written to and that one isn't missing any records. It's
not giving any errors so I don't know what's going on.

I write to the 2nd table first, then do some stuff in my code, then I
begin a transaction, write to the 1st table (as well as a couple
others), then commit the transaction. Does anyone know what could
cause this or how I can diagnose where the problem may be occurring?

Thanks!
Re: Missing records in database... Uri Dimant
11/19/2006 12:00:00 AM
Do you have trigger/s on the table/s? Can you post entire code to reproduce
the problem along with a version of sql server and service pack installed
on?






[quoted text, click to view]

Re: Missing records in database... Tibor Karaszi
11/19/2006 12:00:00 AM
If you rollback, the identity value has been consumed. Do not use identity if you for some reason
require consecutive numbering.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/


[quoted text, click to view]
Re: Missing records in database... hurricane_number_one NO[at]SPAM yahoo.com
11/19/2006 10:04:25 AM
I don't use triggers. I can't reproduce the problem, I just see it
happening at clients by looking in their database. I'm using Recordsets
in VB to write the data. Is it possible for the data to not get stored
like this without throwing an error or is there something else I should
look for?

[quoted text, click to view]
Re: Missing records in database... Aaron Bertrand [SQL Server MVP]
11/19/2006 1:10:59 PM
[quoted text, click to view]

That doesn't necessarily mean a row is missing.
http://databases.aspfaq.com/database/why-are-there-gaps-in-my-identity/autoincrement-column.html

Re: Missing records in database... hurricane_number_one NO[at]SPAM yahoo.com
11/19/2006 11:05:26 PM
I know they are missing because every time a row is written in this
table a receipt is printed out and there are receipts that don't have
corresponding rows in the database and if I look at the timestamp on
the receipt, the place where it would be located in the database has a
missing ID in the sequence.

[quoted text, click to view]
Re: Missing records in database... David Portas
11/19/2006 11:41:56 PM
[quoted text, click to view]

Maybe the INSERT itself is failing, due to a constraint violation for
example. Are you properly capturing any errors in your insert procs?
The other possibility is that some other process deletes rows without
you realising. It is far more likely that the rows never committed or
were deleted than that the data is "corrupt" in some way. One way to
track this down is to use a Profiler trace to capture any SQL
statements against your table.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Re: Missing records in database... hurricane_number_one NO[at]SPAM yahoo.com
11/21/2006 2:16:37 PM
I have made sure that all errors are properly logged. I also added
some code which logs every step and the logs show that it is starting
the transaction, updating/inserting the recordset then comitting the
transactions all fine without any errors but I'm still getting missing
rows now and then. This is only happenning when I'm doing a transaction
that involves updating many tables.

[quoted text, click to view]
AddThis Social Bookmark Button