重置自动编号种子

发布于 2024-08-22 05:59:43 字数 689 浏览 9 评论 0原文

我有一个 VB6/Access 应用程序,偶尔会遇到自动编号字段种子错误的问题。

假设有一个带有自动编号字段 ID(也是主键)的表 MYTABLE。假设目前 ID 的最大值为 1000。当应用程序插入一条新记录(未明确提供 ID 值)时,由于某种原因,它决定下一个自动编号字段值为 950(而不是应有的 1001) ) - 因此会发生主键冲突错误。

我找到了一篇描述我的症状的知识库文章:http://support.microsoft.com/kb/884185< /a> .简而言之,他们建议运行一个查询:

ALTER TABLE MYTABLE ALTER COLUMN ID COUNTER(1001,1)

当我尝试执行此操作时,它会失败并显示“无效的字段数据类型”。

如果我在 Access 中打开数据库并进行压缩/修复,问题就会得到解决,但我需要能够修复应用程序内部的此类问题:它安装在世界各地数千台 PC 上,要求人们使用 Access 进行压缩/修复不是一个选项。

我使用 DAO DBEngine.CompactDatabase 在应用程序内部执行压缩/修复,但它不能解决种子问题,并且需要一些额外的技巧。

有解决方案的想法吗?

I have a VB6/Access application that occasionally encounters a problem with wrong autonumber field seed.

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.

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"

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.

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.

Any ideas for a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

给妤﹃绝世温柔 2024-08-29 05:59:43

请参考以下文章,它包含您可以添加到访问项目中以执行以重置播种的方法。过去,它多次为我节省了时间:

http://allenbrowne.com/ser-40 .html

除此之外,它还对此类问题的原因和潜在解决方案进行了解释和深入分析。

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.

记忆消瘦 2024-08-29 05:59:43

您可能还需要确保数据库设置为使用 ANSI 92,以便 COUNTER 被识别为合法数据类型。

在 Access 2007 中,转到Access 选项、对象设计器、SQL Server 兼容性语法 (ANSI 92) 进行设置。

You may also need to make sure that your database is set up to use ANSI 92 so that COUNTER is recognized as a legitimate data type.

In Access 2007 go to Access Options, Object Designers, SQL Server compatability syntax (ANSI 92) to set this.

渡你暖光 2024-08-29 05:59:43

您也许可以通过压缩/修复来解决问题:

In Access 2010:  Compact and Repair Database on the Database Tools ribbon.
In Access 2007:  Office Button | Manage.
In earlier versions:  Tools | Database Utilities.

You may be able to solve the problem with a compact/repair:

In Access 2010:  Compact and Repair Database on the Database Tools ribbon.
In Access 2007:  Office Button | Manage.
In earlier versions:  Tools | Database Utilities.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文