【问题标题】:How to automatically logout users or have user sessions timeout in MS Access如何在 MS Access 中自动注销用户或使用户会话超时
【发布时间】:2019-05-20 05:24:39
【问题描述】:

我们的一个客户有一个不断崩溃的 MS Access 数据库。我们的 IT 部门认为它崩溃了,因为,1. 只有一个登录,2. 多个人在不同的机器上同时使用相同的登录,3. 相同的人在不使用数据库时离开他们的会话登录。

我认为这个问题可以通过切换到 SQL Server 来解决,并且每个人都有自己的登录名。一,它有助于审计跟踪,二,并发、会话超时和其他设置可用。此解决方案的问题是客户端不想迁移到 SQL Server。

所以我的问题是,Access 是否具有在 X 不活动时间后自动注销用户会话的功能?如果是这样,谁能提供有关如何启用此功能的文档或链接?

【问题讨论】:

  • 我相信答案是否定的。我已经看到许多讨论如何在一段时间不活动后关闭 Access 的线程。 Google 或 Bing 应该会有所帮助。 blueclaw-db.com/download/user_inactivity_logout.htm, stackoverflow.com/questions/11055103/auto-logoff-of-ms-access
  • 嗯,不清楚您所说的一次登录是什么意思?那不会影响任何事情。在这里使用术语登录并不清楚。这个数据库是分裂的吧?该应用程序安装在每个工作站上。如果不是,那么这就是应用程序不稳定的第一大原因。你说的是哪种登录方式?

标签: ms-access


【解决方案1】:

在on timer属性上用如下代码创建一个隐藏表单(定时器间隔设置为1000)

Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
   ' running the IdleTimeDetected subroutine.
   Const IDLEMINUTES = 60

   Static PrevControlName As String
   Static PrevFormName As String
   Static ExpiredTime

   Dim ActiveFormName As String
   Dim ActiveControlName As String
   Dim ExpiredMinutes

   On Error Resume Next

   ' Get the active form and control name.

   ActiveFormName = Screen.ActiveForm.Name
   If Err Then
      ActiveFormName = "No Active Form"
      Err = 0
   End If

   ActiveControlName = Screen.ActiveControl.Name
      If Err Then
      ActiveControlName = "No Active Control"
      Err = 0
   End If

   ' Record the current active names and reset ExpiredTime if:
   '    1. They have not been recorded yet (code is running
   '       for the first time).
   '    2. The previous names are different than the current ones
   '       (the user has done something different during the timer
   '        interval).
   If (PrevControlName = "") Or (PrevFormName = "") _
     Or (ActiveFormName <> PrevFormName) _
     Or (ActiveControlName <> PrevControlName) Then
      PrevControlName = ActiveControlName
      PrevFormName = ActiveFormName
      ExpiredTime = 0
   Else
      ' ...otherwise the user was idle during the time interval, so
      ' increment the total expired time.
      ExpiredTime = ExpiredTime + Me.TimerInterval
   End If

   ' Does the total expired time exceed the IDLEMINUTES?
   ExpiredMinutes = (ExpiredTime / 1000) / 60
   If ExpiredMinutes >= IDLEMINUTES Then
      ' ...if so, then reset the expired time to zero...
      ExpiredTime = 0
      ' ...and call the IdleTimeDetected subroutine.
      IdleTimeDetected ExpiredMinutes
   End If
End Sub

Sub IdleTimeDetected(ExpiredMinutes)
   DoCmd.OpenForm "CountToExit"
End Sub

在计时器设置中创建一个弹出表单,并包含以下内容。

' GRACEMINUTES determines how much idle time to count down once this form
' is opened before quitting the Access application.
Const GRACEMINUTES = 1
Static ElapsedTime As Integer
Dim TimeRemaining As Integer
Dim intMinutes As Integer
Dim intSeconds As Integer
Dim strTimePassed As String
Dim strOutput As String

On Error Resume Next
ElapsedTime = ElapsedTime + 1    ' Counts seconds instead of milliseconds.
ElapsedMinutes = ElapsedTime / 60
TimeRemaining = (GRACEMINUTES * 60) - ElapsedTime

 ' Has the countdown timer run out?
If TimeRemaining <= 0 Or Not IsNumeric(TimeRemaining) Then
 ' ...if so, then exit Access.
   strOutput = "0:00"
   Application.Quit acSaveNo
Else
   intMinutes = Fix(TimeRemaining / 60)
   intSeconds = TimeRemaining - (intMinutes * 60)
   strOutput = Format(intMinutes, "0") & ":" & Format(intSeconds, "00")
End If
    Me.Label3.Caption = "Auto shutdown timer: " & strOutput
End Sub

使用您的自动执行程序启动该隐藏表单,它会每秒检查一次以查看此人是否更改了 Access 中的窗口。在 60 分钟不做任何事情后,他们会收到一个警告窗口,告诉他们在访问保存和退出之前有 60 秒的时间关闭弹出窗口。

【讨论】:

    【解决方案2】:

    访问崩溃的原因之一是数据的大小。如果我没记错的话,限制在 2GB 左右。如果您每次用户关闭应用程序时都进行压缩和修复,它将帮助您最大限度地减少崩溃。您可以通过更新访问数据库的设置来更改它。

    【讨论】:

      猜你喜欢
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多