重置自动编号种子 [英] Reset autonumber seed
问题描述
我有一个VB6/Access应用程序,偶尔会遇到错误的自动编号字段种子问题.
I have a VB6/Access application that occasionally encounters a problem with wrong autonumber field seed.
可以说有一个表MYTABLE带有一个自动编号字段ID(也是主键).可以说,当前ID的最大值为1000.当应用程序插入新记录(未明确提供ID值)时,由于某种原因,它决定下一个自动编号字段值为950(而不是应为1001). )-这样就会发生主键冲突错误.
Lets say there is a table MYTABLE with an autonumber field ID (that is also the primary key). Lets say at the moment the maximum value of ID is 1000. When the application inserts a new record (ID value is not provided explicitly), for some reason it decides that the next autonumber field value is 950 (and not 1001 as it should be) - so a primary key violation error occurs.
我找到了一篇描述我的症状的知识库文章: http://support.microsoft.com/kb /884185 .简而言之,他们建议运行查询:
I found a KB article that describes my symptoms: http://support.microsoft.com/kb/884185 . In short, they suggest to run a query:
ALTER TABLE MYTABLE ALTER COLUMN ID COUNTER(1001,1)
当我尝试执行此操作时,它失败,并显示无效的字段数据类型"
When I try to do this, it fails with "Invalid field data type"
如果我在Access中打开数据库并执行压缩/修复操作,该问题将得到解决,但是我需要能够修复应用程序内部的此类问题:它已安装在世界各地的数千台PC上,并询问人们无法使用Access进行压缩/修复.
The problem gets fixed if I open the database in Access and do compact/repair, but I need to be able to fix such problems inside the application: it is installed on a couple of thousands of PCs around the world, and asking people to compact/repair with Access is not an option.
我使用DAO DBEngine.CompactDatabase
在应用程序内部执行压缩/修复,但不能解决种子问题,还需要一些其他技巧.
I use DAO DBEngine.CompactDatabase
to perform compact/repair inside the application, but it doesn't fix the seed problem, and some additional tricks are needed.
有解决方案的想法吗?
推荐答案
请参考以下文章,它包含您可以添加到您的访问项目中以执行以重置种子的方法.在过去的几次中,它为我节省了很多时间:
Please reference the following article, it contains a method you may add to your access project to execute to reset seeding. It has been a saver for me several occasions in the past:
http://allenbrowne.com/ser-40.html
除此之外,它还提供了对此类问题的原因和潜在解决方案的解释和见解.
In addition to this it gives explanation and insight into causes and potential resolution for such problems.
这篇关于重置自动编号种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!