0

在 Citrix 下针对 SQL Server 2008R2 后端运行 MS Access 2010 前端。

我有一个已经工作了一段时间的表格。一个按钮背后的代码突然开始产生“写入冲突”错误。它发生在几天前,经过几个小时的不变代码(通过在线文本比较工具确认),并让另一个程序员在这里查看它,我唯一的解决方案是抓住前端的生产版本并开始重新应用我的更改。

它已经运行了 2 天,现在错误再次发生。我正在更改代码,但形式不同。我需要完成此表格上的流程才能测试其他表格。

这是产生写入冲突的代码:

Private Sub btnStart_Click()

Dim AuditID As String
Dim UserStatus As String
Dim SubmitPeerRev As Boolean
Dim PRPercent As Single
Dim ExaminerAudits As Integer
Dim ReviewAudits As Integer
Dim rs As DAO.Recordset
Dim UserName As String
Dim SQLString As String

    On Error GoTo Error_Handler

    UserStatus = funUserLookup("Status", Raw:=True)
    'get the percentage/whole number
    'this is the percentage that should be submitted for review
    If IsNull(DLookup("ItemValue", "tblConfig", "Item = '" & UserStatus & "'")) Then
        Form_frmMenu.MsgBoxTimed ("Your user ID is not configured correctly within the     AP_Audit DB." & vbCrLf & _
            "You cannot start an audit." & vbCrLf & _
            "Please contact your manager to get it set correctly.")
        Exit Sub
    Else
        PRPercent = CSng(DLookup("ItemValue", "tblConfig", "Item = '" & UserStatus & "'"))
    End If
    UserName = funUserLookup("Examiner")

    'get total audits done
    SQLString = "SELECT count(*) as A " & _
                "  FROM tblAuditAtt " & _
                " WHERE Examiner = '" & UserName & "'" & _
                "   AND month(aMonth) = " & Month(Now()) & _
                "   AND year(aMonth) = " & Year(Now())
    Set rs = CurrentDb.OpenRecordset(SQLString, dbOpenDynaset)
    ExaminerAudits = rs.Fields("[A]")

    'get peer-reviewed audits done
    SQLString = "SELECT count(*) as A " & _
                    "  FROM tblAuditAtt " & _
                    " WHERE TraineeExaminer = '" & UserName & "'" & _
                    "   AND Month(aMonth) = " & Month(Now()) & _
                    "   AND Year(aMonth) = " & Year(Now())
    Set rs = CurrentDb.OpenRecordset(SQLString, dbOpenDynaset)
    ReviewAudits = rs.Fields("[A]")
    Set rs = Nothing

    If DLookup("Started", "tblAuditAtt", "AttAudit_ID = " & Me.AttAudit_ID) Then
        Form_frmMenu.MsgBoxTimed "This audit was already started by someone else. Select a new one."
        Me.Requery
        Exit Sub
    End If
        'UserName = funUserLookup("Examiner")
        If ReviewAudits = 0 Then            'ensure 1 review - prevents divide by 0
            Me.TraineeExaminer = UserName
            Me.TraineeExaminer.Visible = True
            Me.TraineeExaminer.Top = 2280
            Me.Examiner.Visible = False
        ElseIf ExaminerAudits = 0 And PRPercent < 1 Then      'ensure 1 non-review if < 100% peer-review
            Me.Examiner = UserName
            Me.TraineeExaminer.Visible = False
            Me.Examiner.Visible = True
        ElseIf ExaminerAudits / (ExaminerAudits + ReviewAudits) > 0.99999999 - PRPercent Then
            'the tiny fraction is needed because 0 > 0 = false & 100% trainees would get a straight submit
            Me.TraineeExaminer = UserName
            Me.TraineeExaminer.Visible = True
            Me.TraineeExaminer.Top = 2280
            Me.Examiner.Visible = False
        Else
            Me.Examiner = UserName
            Me.TraineeExaminer.Visible = False
            Me.Examiner.Visible = True
        End If

    Me.StartDate = Format(Form_frmMenu.GetSQLTime, "mm/dd/yyyy")
    Me.Started = True
    Me.Dirty = False
    Form_frmMenu.ExecSP "AUDIT_AttAuditStart", 120, False, "@AuditID", adInteger, Me.AttAudit_ID
    'this is failing, for reasons yet unknown, so only continue if it hasn't
    If Nz(DLookup("AttAudit_A", "tblAuditAtt_A", "AttAudit_ID = " & Me.AttAudit_ID), 0) > 0 Then
        Me.btnStartEnd.Enabled = True
        Me.btnStartEnd.SetFocus
        Me.btnStart.Enabled = False
        Me.frmAttAudit_A_Sub.Requery
        SetSubFormView  'now that we know what type of audit & have questions, set up the proper view
    Else
        Me.TraineeExaminer = ""
        Me.Examiner = ""
        Me.StartDate = ""
        Me.Started = False
        Me.Dirty = False
        SQLString = Form_frmMenu.LogError(0, "Audit did not start properly", "User Defined", "frmAttAudit_A.btnStart_Click", "Stored procedure failed to insert records")
    End If

    Exit Sub

Error_Handler:
    If Form_frmMenu.LogError(err.Number, err.Description, err.Source, "frmAttAudit_A.btnStart_Click", SQLString) = "Next" Then
        Resume Next
    Else
            Resume
        End If

    End Sub

笔记:

  • 我在我们的开发服务器上运行它,我是唯一使用这些表的人
  • 我添加了一个时间戳列,这似乎没有任何区别
  • 我已将me.dirty = false代码移至每次绑定表单字段更改后,但这无济于事
  • 以前唯一的解决方案是获取生产代码并手动重新应用我的所有更改。
  • 您可以看到还有另一个奇怪的问题导致插入查询失败。不知道改调用存储过程以后有没有出现过,但是有docmd.runsql语句的时候就失败了
  • 我在另一篇文章中收到了在 Citrix 环境中禁用挂钩的建议,因为这可能会搞砸事情,但我们的 IT 人员不会对此进行调查。

有关如何解决此问题的任何其他想法或建议?当 Access 决定呕吐时,我真的没有时间每隔几天重做一次工作。

4

1 回答 1

0

如果底层的 sql server 表有空值的位字段,这可能会导致通过 odbc 链接到 sql server 时访问时出现写入冲突错误。它与访问有关,首先将空位值转换为 0,然后尝试应用您所做的更改并导致写入冲突。

就我而言,我通过将新位字段默认为 0 并将现有字段上的空值替换为 0 来解决它。

于 2013-11-14T17:24:08.277 回答