简体   繁体   中英

Access front-end, SQL Server back-end skipping autonumber IDs

Question title is the crux of the problem. I have an Access 2007 (2003 format) front-end with a SQL Server 2008 Express back-end. The input form has a subform linked to another table. When adding a record in the main form, the PK field of the table (set to auto increment) is skipping about four IDs (I say about because sometimes it's three, sometimes five, sometimes 4).

To illustrate, if the last ID is 1234, the ID of the new record might be 1238.

I've stepped through the code, but haven't found anything that would indicate multiple saves or deletes. This problem manifests regardless of whether any records are added to the subform.

I realize this could be anything, but I'm hoping someone might have some insight or suggestions of avenues to investigate.

可能是表中的某些INSERT在事务中完成,然后又回滚了该事务-这会用完ID,留下空白。

Check the Identity specification on the database to see what the Identity Increment is. It may be incrementing at an interval greater than 1, though that wouldn't explain your odd numbering. It's a good starting point.

Also, you could be having people start a record and then deleting it ala the transactions being rolled back and the incrementer being increased.

fire up sql profiler and observer the RPC:Completed and SqlStmt:Completed events to see what exactly is getting executed.

SQL Server doesn't just skip numbers for no reason. it looks like it's inserting something and rolling it back or inserting rows fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM