数据保存时,出现‘record not found or changed by another user’错误信息的解决办法

本文探讨了在使用TDataSetProvider进行数据更新时遇到的'recordnotfoundorchangedby anotheruser'错误。通过调整UpdateMode参数及正确设置主键字段,可以有效避免此问题。

'record not found or changed by  another user',这个错误是我在做项目时,遇到的问题,找了一些参考才解决。如下:
所用的控件有:TDataSetProvider,TADOQuery,TClientDataSet
1.当 DataSetProvider.UpdateMode=upWhereAll 时,update时 where 是指定全部字段,比如,你有a、b、c 3个字段,修改了c字段,在app server中修改的命令是update ... set c=新c where a=旧a and b=旧b and c=旧c
如果 旧的a、b、c之一 已经被其他人改掉了,那where就找不到合适的记录来修改了。所以报告“记录被其他人修改”,这个问题和“锁定”是无关的。

2.当 DataSetProvider.UpdateMode=upWhereKeyOnly 时,update时 where 是指定key字段,比如,
你有a、b、c 3个字段,修改了c字段,a是key field在app server中修改的命令是
update ... set c=新c where a=旧a (只比较a字段)你的程序应该设计为客户修改不到主键字段的值,这样
你的客户只能修改到其他字段的值,其他字段不会出现在where中,就不会出现你说的问题了。

(用第2种方法解决,注意如果你的表原来没有主键的,需要双击dataset,添加你的所有field,在有唯一值的field的 ProviderFlasgs 属性里面 InKey 设置为 true (该field必须是有唯一值的,能相当于主键的,也就是能唯一确定该行记录的),TADOQuery,TClientDataSet控件里的唯一值的field字都要设置InKey为true)

翻译成中文,只做翻译: 9. Conflict Resolution A conflict occurs when a Multicast DNS responder has a unique record for which it is currently authoritative, and it receives a Multicast DNS response message containing a record with the same name, rrtype and rrclass, but inconsistent rdata. What may be considered inconsistent is context sensitive, except that resource records with identical rdata are never considered inconsistent, even if they originate from different hosts. This is to permit use of proxies and other fault-tolerance mechanisms that may cause more than one responder to be capable of issuing identical answers on the network. A common example of a resource record type that is intended to be unique, not shared between hosts, is the address record that maps a host's name to its IP address. Should a host witness another host announce an address record with the same name but a different IP address, then that is considered inconsistent, and that address record is considered to be in conflict. Whenever a Multicast DNS responder receives any Multicast DNS response (solicited or otherwise) containing a conflicting resource record in any of the Resource Record Sections, the Multicast DNS responder MUST immediately reset its conflicted unique record to probing state, and go through the startup steps described above in Section 8, "Probing and Announcing on Startup". The protocol used in the Probing phase will determine a winner and a loser, and the loser MUST cease using the name, and reconfigure. It is very important that any host receiving a resource record that conflicts with one of its own MUST take action as described above. In the case of two hosts using the same host name, where one has been configured to require a unique host name and the other has not, the one that has not been configured to require a unique host name will not perceive any conflict, and will not take any action. By reverting to Probing state, the host that desires a unique host name will go through the necessary steps to ensure that a unique host name is obtained. The recommended course of action after probing and failing is as follows: 1. Programmatically change the resource record name in an attempt to find a new name that is unique. This could be done by adding some further identifying information (e.g., the model name of the hardware) if it is not already present in the name, or appending the digit "2" to the name, or incrementing a number at the end of the name if one is already present. 2. Probe again, and repeat as necessary until a unique name is found. 3. Once an available unique name has been determined, by probing without receiving any conflicting response, record this newly chosen name in persistent storage so that the device will use the same name the next time it is power-cycled. 4. Display a message to the user or operator informing them of the name change. For example: The name "Bob's Music" is in use by another music server on the network. Your music collection has been renamed to "Bob's Music (2)". If you want to change this name, use [describe appropriate menu item or preference dialog here]. The details of how the user or operator is informed of the new name depends on context. A desktop computer with a screen might put up a dialog box. A headless server in the closet may write a message to a log file, or use whatever mechanism (email, SNMP trap, etc.) it uses to inform the administrator of error conditions. On the other hand, a headless server in the closet may not inform the user at all -- if the user cares, they will notice the name has changed, and connect to the server in the usual way (e.g., via web browser) to configure a new name. 5. After one minute of probing, if the Multicast DNS responder has been unable to find any unused name, it should log an error message to inform the user or operator of this fact. This situation should never occur in normal operation. The only situations that would cause this to happen would be either a deliberate denial-of-service attack, or some kind of very obscure hardware or software bug that acts like a deliberate denial-of-service attack. These considerations apply to address records (i.e., host names) and to all resource records where uniqueness (or maintenance of some other defined constraint) is desired.
最新发布
10-18
在 Ubuntu 系统中使用 Alist 时遇到 **'Failed to find user: record not found'** 错误,通常表明系统无法找到指定的用户记录。该问题可能由多种原因引起,以下是常见的几种情况及其解决方法。 ### 数据库配置错误 Alist 使用数据库来存储用户信息。如果数据库连接配置错误或数据库中缺少必要的用户表,则会导致无法查询到用户记录。请检查 `config.json` 或相关配置文件中的数据库设置是否正确,确保数据库服务正在运行,并且可以访问所需的表[^1]。 ### 用户未正确注册或创建 如果用户尚未通过注册流程创建账户,或者管理员未手动添加用户,则会出现此错误。可以通过 Alist 的管理界面或直接操作数据库来确认用户是否存在。若不存在,应重新创建用户[^1]。 ### 数据库表结构不完整 有时数据库表结构可能未正确初始化或更新,导致某些字段缺失。检查数据库中的用户表(例如 `users` 表)是否包含必要的字段,如 `username`, `password`, `created_at` 等。如果字段缺失,需根据官方文档进行修复或迁移[^1]。 ### 查询语句逻辑错误 在代码层面,可能存在对用户数据的查询逻辑错误。例如,查询条件拼写错误、字段名不匹配等问题。检查 Alist 的日志输出,查看具体的 SQL 查询语句是否正确执行。若有错误,需调整查询逻辑以确保能够正确检索用户信息[^3]。 ### 权限问题 如果数据库用户没有足够的权限访问用户表,也可能导致无法读取用户记录。确认数据库用户的权限设置,确保其具有 `SELECT`, `INSERT`, `UPDATE` 等必要权限。 ### 缓存问题 Alist 可能会缓存用户数据以提高性能,但如果缓存未能及时更新,可能导致旧数据被使用。尝试清除缓存并重启 Alist 服务,以确保加载最新的用户信息[^1]。 ### 示例:检查数据库连接配置 ```json { "driver": "sqlite3", "source": "./data.db" } ``` 确保以上配置指向正确的数据库类型和路径,并验证数据库文件是否存在且可读[^1]。 ### 示例:检查用户是否存在 ```sql SELECT * FROM users WHERE username = 'testuser'; ``` 运行上述 SQL 语句检查特定用户是否存在。如果返回空结果,则需要重新创建用户。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值