访问报告数据库“不一致”

时间:2019-07-09 05:48:09

标签: database ms-access

昨天,我将数据库分为两部分-它们位于网络驱动器上((前端和后端))-我使用内置的Access选项进行了此操作。我将后端隐藏在一个只有我可以访问的文件中,并将前端提供给一些测试人员使用(他们昨天没有尝试更改任何东西,直到今天我才通知他们)。来自前端的所有链接都是正确的,它们通向我的后端。但是,今天,在与测试人员共享数据库之前,我收到了这样的消息(在打开前端数据库时):Microsoft Access已检测到数据库不一致,并将尝试恢复该数据库。在此过程中,将备份数据库,并将所有对象放置在新数据库中。 Access将随后打开新数据库。无法恢复的对象名称将在“恢复错误”表中注册。我在Microsoft网站上找到了他们知道的有关该问题的信息,但通常没有任何增加。有没有办法做到这一点,还是我们必须等待他们修复它?上面提到的链接是:https://support.office.com/en-us/article/access-reports-that-databases-are-in-an-inconsistent-state-%EF%BB%BF-7ec975da-f7a9-4414-a306-d3a7c422dc1d

1 个答案:

答案 0 :(得分:1)

  

例如,如果我更改表单中的某些内容(我将添加一个按钮),   必须将新版本的表单“发送”给20个用户?

是的。但是我写了一篇文章,介绍如何使用快捷方式和脚本顺利进行此操作:

Deploy and update a Microsoft Access application with one click

如果您没有帐户,请浏览链接:阅读全文

脚本:

Option Explicit

' Launch script for a Microsoft Access application.
' Version 2.0.2
' 2019-01-15
' Cactus Data. Gustav Brock

' ---------------------------------------------------------------------------------
' This script file must be placed in a distribution folder, like:
'   F:\Distribution\AppName
'
' That folder must have subfolder(s) for the app type(s).
' - for one app type only, for example:
'   F:\Distribution\AppName\Files
' - for, say, three app types:
'   F:\Distribution\AppName\Operations
'   F:\Distribution\AppName\Test
'   F:\Distribution\AppName\Development
'
' Specify the next constants for a resulting install path of:
'   %LocalAppData%\OrgSubfolderName\AppSubfolderName\AppTypeSubfolderName
' - for example resulting in:
'   C:\Users\UserProfileName\AppData\Local\Organisation\AppName\Operations
' ---------------------------------------------------------------------------------

' ---------------------------------------------------------------------------------
' Environment specific constants.
    '
    ' Expected version of Microsoft Access - the returned value of property:
    '   ? Access.Application.Version
    Const AccessVersion = "16.0"
' ---------------------------------------------------------------------------------

' ---------------------------------------------------------------------------------
' Application specific constants.
    '
    ' Source filename.
    Const AppBaseName = "DMadresser"
    ' Extension name. Uncomment ONE extension name only.
    'Const AppExtensionName = "accdb"
    'Const AppExtensionName = "accde"
    Const AppExtensionName = "accdr"
    ' Optional suffix.
    Const AppNoColourSuffix = "NC"

    ' Local install folder names. Will be (sub)subfolders of %LocalAppData%.
    Const OrgSubfolderName = "DM"
    Const AppSubfolderName = "DM Administration"

    ' Shortcut name(s). Uncomment ONE folder name ONLY:
    Const ShortcutBaseName = "DM Adresser"
    'Const ShortcutBaseName = "DM Adresser Test"

    ' Title of the application when running. For TaskKill in subfunction KillTask.
    Const AppWindowTitle = "DM ADRESSER"
' ---------------------------------------------------------------------------------

' ---------------------------------------------------------------------------------
' Installation specific constants.

    ' Distribution folder names. Uncomment ONE folder name ONLY:
    Const AppTypeSubfolderName = "Files"
    'Const AppTypeSubfolderName = "Development"
    'Const AppTypeSubfolderName = "Operations"
    'Const AppTypeSubfolderName = "Test"

    ' Indicate if the script is for the normal version (0) or a no-colour version (1):
    Const NoColour = 0

    ' Force a close of an open application even if blocked by a modal message box.
    Const ForceClose = True
' ---------------------------------------------------------------------------------


' ---------------------------------------------------------------------------------
' Script.

    ' Windows folder constants.
    Const DESKTOP = &H10
    Const LOCALAPPDATA = &H1C
    ' Extension of a shortcut.
    Const ShortcutExtensionName = "lnk"

    ' Objects.
    Dim FileSystemObject
    Dim AppShell
    Dim DesktopFolder
    Dim LocalAppDataFolder
    Dim LocalFolder
    Dim RemoteFolder

    ' Variables.
    Dim LocalFolderName
    Dim RemoteFolderName
    Dim DesktopFolderName
    Dim LocalAppDataFolderName
    Dim LocalAppDataOrgFolderName
    Dim LocalAppDataOrgAppFolderName
    Dim AppName
    Dim AppExtension
    Dim AppSuffix
    Dim ShortcutName
    Dim AppLocalPath
    Dim AppRemotePath
    Dim ShortcutExtension
    Dim ShortcutLocalPath
    Dim ShortcutRemotePath
    Dim RegPath
    Dim RegKey
    Dim RegValue
    Dim Value


    ' Create the Shell object and the File System Object.
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set AppShell = CreateObject("Shell.Application")

    ' Build distribution folder name.
    RemoteFolderName = FileSystemObject.GetParentFolderName(WScript.ScriptFullName)

    ' Build filenames.
    If NoColour = 1 Then
        AppSuffix = AppNoColourSuffix
    Else
        AppSuffix = ""
    End If
    AppExtension = "." & AppExtensionName
    AppName = AppBaseName & AppSuffix & AppExtension
    ShortcutExtension = "." & ShortcutExtensionName
    ShortcutName = ShortcutBaseName & AppSuffix & ShortcutExtension

    ' Enable in-line error handling.
    On Error Resume Next

    ' Find user's Desktop and AppData\Local folder.
    Set DesktopFolder = AppShell.Namespace(DESKTOP)
    DesktopFolderName = DesktopFolder.Self.Path
    Set LocalAppDataFolder = AppShell.Namespace(LOCALAPPDATA)
    LocalAppDataFolderName = LocalAppDataFolder.Self.Path

    ' Uncomment to debug.
    'WScript.Echo "Desktop: " & DesktopFolderName & vbCrLf & "LocalAppData: " & LocalAppDataFolderName

    ' Dynamic parameters.
    LocalAppDataOrgFolderName = FileSystemObject.BuildPath(LocalAppDataFolderName, OrgSubfolderName)
    LocalAppDataOrgAppFolderName = FileSystemObject.BuildPath(LocalAppDataOrgFolderName, AppSubfolderName)
    LocalFolderName = FileSystemObject.BuildPath(LocalAppDataOrgAppFolderName, AppTypeSubfolderName)
    AppLocalPath = FileSystemObject.BuildPath(LocalFolderName, AppName)
    ShortcutLocalPath = FileSystemObject.BuildPath(DesktopFolderName, ShortcutName)

    ' Permanent parameters.
    AppRemotePath = FileSystemObject.BuildPath(RemoteFolderName, AppName)
    ShortcutRemotePath = FileSystemObject.BuildPath(FileSystemObject.BuildPath(RemoteFolderName, ".."), ShortcutName)

    ' Verify/create the local folders.
    If Not FileSystemObject.FolderExists(RemoteFolderName) Then
        Call ErrorHandler("No access to " & RemoteFolderName & ".")
    Else
        Set RemoteFolder = FileSystemObject.GetFolder(RemoteFolderName)
        ' If the local folder does not exist, create the folder.
        If Not FileSystemObject.FolderExists(LocalFolderName) Then
            If Not FileSystemObject.FolderExists(LocalAppDataOrgFolderName) Then
                Set LocalFolder = FileSystemObject.CreateFolder(LocalAppDataOrgFolderName)
                If Not Err.Number = vbEmpty Then
                    Call ErrorHandler("Folder " & LocalAppDataOrgFolderName & " could not be created.")
                End If
            End If
            If Not FileSystemObject.FolderExists(LocalAppDataOrgAppFolderName) Then
                Set LocalFolder = FileSystemObject.CreateFolder(LocalAppDataOrgAppFolderName)
                If Not Err.Number = vbEmpty Then
                    Call ErrorHandler("Folder " & LocalAppDataOrgAppFolderName & " could not be created.")
                End If
            End If
            If Not FileSystemObject.FolderExists(LocalFolderName) Then
                Set LocalFolder = FileSystemObject.CreateFolder(LocalFolderName)
                If Not Err.Number = vbEmpty Then
                    Call ErrorHandler("Folder " & LocalFolderName & " could not be created.")
                End If
            End If
        End If
        Set LocalFolder = FileSystemObject.GetFolder(LocalFolderName)
    End If

    ' Copy the distribution file to the local folder and the shortcut to the Desktop.
    If Not FileSystemObject.FileExists(AppRemotePath) Then
        Call ErrorHandler("The application file:" & vbCrLf & AppRemotePath & vbCrLf & "could not be found.")
    Else
        ' First, close a running application - using the setting of constant ForceClose.
        Call KillTask(AppWindowTitle)
        ' Wait while TaskKill is running to close the instance of the application.
        Call AwaitProcess("taskkill.exe")

        ' Copy app to local folder.
        If FileSystemObject.FileExists(AppLocalPath) Then
            FileSystemObject.DeleteFile(AppLocalPath)
            If Not Err.Number = 0 Then
                If IsProcess("MSACCESS.EXE") Then
                    ' The application may be blocked for closing by a modal message box.
                    MsgBox "Cannot update or reinstall the application while it is running.", vbCritical + vbOkOnly, AppWindowTitle
                    WScript.Quit        
                Else
                    Call ErrorHandler("The application file:" & vbCrLf & AppName & vbCrLf & "can not be refreshed/updated. It may be in use.")
                End If
            End If
        End If
        If FileSystemObject.FileExists(AppLocalPath) Then
            Call ErrorHandler("The local application file:" & vbCrLf & AppLocalPath & vbCrLf & "could not be replaced.")
        Else
            FileSystemObject.CopyFile AppRemotePath, AppLocalPath
            If Not Err.Number = vbEmpty Then
                Call ErrorHandler("Application could not be copied to " & LocalFolderName & ".")
            End If
        End If

        ' Uncomment to debug.
        'WScript.Echo "Shortcut remote: " & ShortcutRemotePath & vbCrLf & "Shortcut local: " & ShortcutLocalPath

        ' Copy shortcut.
        FileSystemObject.CopyFile ShortcutRemotePath, ShortcutLocalPath
        If Not Err.Number = vbEmpty Then
            Call ErrorHandler("Shortcut could not be copied to your Desktop.")
        End If
    End If

    ' Write Registry entries for Microsoft Access security.
    RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & AccessVersion & "\Access\Security\"
    RegValue = "VBAWarnings"
    RegPath = RegKey & RegValue
    Value = 1
    Call WriteRegistry(RegPath, Value,"REG_DWORD")

    RegKey = RegKey & "Trusted Locations\LocationLocalAppData\"
    RegValue = "AllowSubfolders"
    RegPath = RegKey & RegValue
    Value = 1
    Call WriteRegistry(RegPath, Value, "REG_DWORD")

    RegValue = "Date"
    RegPath = RegKey & RegValue
    Value = Now
    Value = FormatDateTime(Value, vbShortDate) & " " & FormatDateTime(Value, vbShortTime)
    Call WriteRegistry(RegPath, Value, "REG_SZ")

    RegValue = "Description"
    RegPath = RegKey & RegValue
    Value = "Local AppData"
    Call WriteRegistry(RegPath, Value, "REG_SZ")

    RegValue = "Path"
    RegPath = RegKey & RegValue
    Value = LocalAppDataFolderName & "\"
    Call WriteRegistry(RegPath, Value, "REG_SZ")

    ' Launch the application.
    If FileSystemObject.FileExists(AppLocalPath) Then
        Call RunApp(AppLocalPath)
    Else
        Call ErrorHandler("The local application file:" & vbCrLf & AppLocalPath & vbCrLf & "could not be found.")
    End If

    Set RemoteFolder = Nothing
    Set LocalFolder = Nothing
    Set LocalAppDataFolder = Nothing
    Set DesktopFolder = Nothing
    Set AppShell = Nothing
    Set FileSystemObject = Nothing

    ' Exit.
    WScript.Quit

' Exit script.
' ---------------------------------------------------------------------------------


' ---------------------------------------------------------------------------------
' Supporting (sub)functions.

Sub RunApp(ByVal Filename)

    Const vbNormalFocus = 1
    Const WaitOnReturn = False

    Dim Shell
    Dim Command
    Dim WindowStyle

    ' Open as default foreground application.
    WindowStyle = vbNormalFocus

    Set Shell = CreateObject("WScript.Shell")
    Command = """" & Filename & """"
    Shell.Run Command, WindowStyle, WaitOnReturn

    Set Shell = Nothing

End Sub


Sub KillTask(ByVal WindowTitle)

    Const vbMinimizedNoFocus = 7
    Const WaitOnReturn = False
    Const ForcedCloseOn = "/F"
    Const ForcedCloseOff = ""

    Dim Shell
    Dim Command
    Dim WindowStyle
    Dim CloseStyle

    ' Run silently.
    WindowStyle = vbMinimizedNoFocus

    Set Shell = CreateObject("WScript.Shell")
    If ForceClose = True Then
        CloseStyle = ForcedCloseOn
    Else
        CloseStyle = ForcedCloseOff
    End If
    Command = "TaskKill.exe /FI ""WINDOWTITLE eq " & WindowTitle & """ " & CloseStyle
    Shell.Run Command, WindowStyle, WaitOnReturn

    Set Shell = Nothing

End Sub


Sub AwaitProcess(ByVal Process)

    Dim Service
    Dim Query
    Dim Processes
    Dim Count

    Set Service = GetObject("winmgmts:root\cimv2")
    Query = "select * from win32_process where name = '" & Process & "'"

    Do
        Set Processes = Service.Execquery(Query)
        Count = Processes.Count
        If Count > 0 Then
            WScript.Sleep 300
        End If
    Loop Until Count = 0

    Set Processes = Nothing
    Set Service = Nothing

End Sub

Function IsProcess(ByVal Process)

    Dim Service
    Dim Query
    Dim Processes
    Dim Result

    Set Service = GetObject("winmgmts:root\cimv2")
    Query = "select * from win32_process where name = '" & Process & "'"

    Set Processes = Service.Execquery(Query)
    If Processes.Count > 0 Then
        Result = True
    Else
        Result = False
    End If

    Set Processes = Nothing
    Set Service = Nothing

    IsProcess = Result

End Function


Sub WriteRegistry(ByVal RegPath, ByVal Value, ByVal RegType)
    ' RegType should be:
    '   "REG_SZ" for a string
    '   "REG_DWORD" for an integer
    '   "REG_BINARY" for a binary or boolean
    '   "REG_EXPAND_SZ" for an expandable string

    Dim Shell

    Set Shell = CreateObject("WScript.Shell")

    Call Shell.RegWrite(RegPath, Value, RegType)

    Set Shell = Nothing

End Sub


Sub ErrorHandler(Byval Message)

    Set RemoteFolder = Nothing
    Set LocalFolder = Nothing
    Set LocalAppDataFolder = Nothing
    Set DesktopFolder = Nothing
    Set AppShell = Nothing
    Set FileSystemObject = Nothing

    MsgBox Message, vbExclamation + vbOkOnly, ShortcutBaseName
    WScript.Quit

End Sub


' End script.
' ---------------------------------------------------------------------------------