【发布时间】:2012-08-22 23:02:17
【问题描述】:
我继承了一个脚本,该脚本运行并将记录从一个数据库插入另一个数据库。
直到几天前人们抱怨记录没有从一个系统拉到另一个系统之前,一切似乎都运行良好。
我查看了在 Windows Server 2003 上设置为与计划任务一起运行的宏。该宏将其记录的输出发送到 SQL Server,因此我去那里查找了相应的日志语句,其中读取了一名员工的已插入数据库。然而,当去另一个系统时,据说被转移和插入的员工并不在那里。
经过进一步检查,仅将从一个数据库中选择的字段拉到插入语句中,该语句将它们添加到另一个数据库中。
当我尝试手动插入这些值时,我收到一条 SQL 错误,指出字段不允许为 NULL 或零长度字符串。然而,尽管在脚本中检查错误,
Function SomeFunc
On Error GoTo The_Err
DoCmd.SetWarnings False ' This statement seems a bit suspect to me...maybe fields being
' null or a zero length are just warnings? Seems wrong because
' I don't want a warning when my record will not be inserted,
' I want an error.
....
DoCmd.OpenQuery "qryAddNewEmp_S1toS2", acViewNormal, acAdd ' This is the statement that
' selects from the one db
' and inserts into the other db
...
The_Exit:
Exit Function
The_Err:
' MsgBox Error$ ' You can turn this on and off.
dmsg = "Error AUCP"
RunCheck dmsg, errArea, 0, 0
DoCmd.SetWarnings True
Resume The_Exit
End Function
是否从DoCmd.SetWarnings False 关闭了警告以防止记录错误?我也应该只在代码中进行验证,检查每个值吗?这对我来说似乎不对,这似乎应该是数据库的责任,因为数据库已经内置了。
【问题讨论】:
-
为什么不应该设置警告:stackoverflow.com/questions/11213892/…
-
我还能说什么?这是不该做什么的典型例子。
标签: sql ms-access vba ms-access-2003