2013-10-11 59 views
1

我有一個小型的Access應用程序,只有3或4人會使用,但我希望他們能夠使用它從不同的位置。一次只有一個人會使用它。他們是一個非盈利的,資金很少或沒有。他們沒有服務器,目前在所有人之間來回共享Excel電子表格。我能想到的最簡單的事情就是將.accdb文件上傳到Dropbox帳戶,並讓他們從那裏訪問它。我知道你可以將它發佈到SharePoint,但它們都是Office的本地副本。有沒有問題做Dropbox的事情,或者有沒有更好的選擇你們任何人都可以建議?我可以通過Dropbox共享一個MS-Access數據庫應用程序嗎?

+2

終止交易如果你保證一次只有一個人使用它,那麼DropBox可能工作。但是,您可以通過Access支持獲得一些在線託管服務,每月只需花費幾美元,這對您而言可能會更好。尋找折扣虛擬主機,或者甚至可能有一些公司專門提供Access。 –

+0

我認爲這將取決於嘗試使用DropBox像網絡共享的延遲。當你要求Access做某件事時,它必須在處理之前將所有數據從遠程位置轉移到本地計算機。 – Rikalous

回答

3

我同意在使用Dropbox的文件夾的共享位置可以可能工作前提是隻有一個人有數據庫在任何一個時間開放。如果多人同時打開數據庫,那麼當Dropbox去同步文件時,它可能會打斷別人的更改,或者發生同步衝突,或者只是讓人感到非常困惑。

如果我是用這個方法,我肯定不會依靠告訴用戶「如果有其他人打開它之前使用數據庫經常檢查」,以嘗試或「總是以獨佔模式打開數據庫」。相反,我會使用像下面的VBScript這樣的小啓動腳本來管理對數據庫的訪問。它使用第二個文件擴展名(.Available.IN_USE)來指示數據庫文件的狀態,生成本地(未同步)副本,在Access中打開該副本,然後將更新後的文件複製回Dropbox文件夾,以便它可以同步。

Option Explicit 
Dim WshShell, fso, f, AccessPath, DropboxFolder, WorkingFolder, DatabaseName 
Const TemporaryFolder = 2 

DropboxFolder = "C:\Users\Gord\Dropbox\dbStorage\" 
DatabaseName = "myDatabase.accdb" 

Set fso = CreateObject("Scripting.FileSystemObject") 
WorkingFolder = fso.GetSpecialFolder(TemporaryFolder) & "\" 
If fso.FileExists(DropboxFolder & DatabaseName & ".Available") Then 
    Set f = fso.GetFile(DropboxFolder & DatabaseName & ".Available") 
    f.Name = DatabaseName & ".IN_USE" 
    WScript.Echo "Copying database file to working folder..." 
    f.Copy WorkingFolder & DatabaseName 
    Set f = Nothing 

    Set WshShell = CreateObject("WScript.Shell") 
    AccessPath = WshShell.RegRead("HKEY_CLASSES_ROOT\Access.MDBFile\shell\Open\command\") 
    AccessPath = Left(AccessPath, InStr(AccessPath, "MSACCESS.EXE") + 12) 

    WScript.Echo "Launching Access..." 
    WshShell.Run AccessPath & " """ & WorkingFolder & DatabaseName & """", 1, True 

    WScript.Echo "Copying database file back to Dropbox folder..." 
    fso.CopyFile WorkingFolder & DatabaseName, DropboxFolder & DatabaseName & ".IN_USE" 
    Set f = fso.GetFile(DropboxFolder & DatabaseName & ".IN_USE") 
    f.Name = DatabaseName & ".Available" 
    Set f = Nothing 
Else 
    If fso.FileExists(DropboxFolder & DatabaseName & ".IN_USE") Then 
     MsgBox "The database is currently in use. Try again later." 
    Else 
     MsgBox "The database could not be found." 
    End If 
End If 
Set fso = Nothing 

啓動器可以通過一個快捷方式,其目標是

CSCRIPT.EXE C:\wherever\launchMyDatabase.vbs 
2

這是戈德湯普森腳本的增強版本,它試圖告知用戶,幫助他們做「正確的事」來調用。

它還與異常行爲交易,如不良上網(它鼓勵用戶不使用它!),也與劇本由曾經訪問已經打開的用戶)

' This uses a second file extension (.Available or .InUse) to indicate the status of the database file, 
' makes a local (not synced) copy inthe temp folder and opens that copy in Access. 
' The updated file is copied back to the Dropbox folder so it can be synced. 
' A backup fodler and file can be created with a date in the filename if the suer chooses to. 
' 
' The launcher could be invoked by a shortcut whose target is 
' 
' CSCRIPT.EXE C:\!AA\OpenFMFtoolDatabase.vbs 

' Or to debug (it can open in VS if VS has been setup right with an external tool) 
' CSCRIPT.EXE /X C:\!AA\OpenFMFtoolDatabase.vbs 






' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' This file is used to open and backup the FMFtool university and Subject database 
' 
' It can be invoked by a shortcut whose target is CSCRIPT.EXE C:\!AA\OpenFMFtoolDatabase.vbs 
' 
' See the tag #DOTHESE below for constants that need to be changed for each specific user 


'Option Explicit 

' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' Supporting functions 
' 
Function LPad(MyString, MakeStringThisLong, PadWithThisChar) 

    Dim n: n = 0 
    If MakeStringThisLong > Len(MyString) Then n = MakeStringThisLong - Len(MyString) 
    LPad = String(n, PadWithThisChar) & MyString 

End Function 

Function BuildDateForFile() 

    Dim TheMonth, TheDay 

    TheMonth = LPad(Month(Date), 2, "0") 
    TheDay = LPad(Day(Date), 2, "0") 

    BuildDateForFile = DatePart("yyyy", Now) & TheMonth & TheDay & "_" 

End Function 


' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' ---------------------------------------------------------------------------------------- 
' Main Procedure 
' 
Sub OpenDatabase() 

    ' ----------------------------------------------------------------- 
    ' ----------------------------------------------------------------- 
    ' USER/MACHINE SPECIFIC#DOTHESE 

    Const SupportEmail = "[email protected]" 
    ' This script may prompt the user to contact support using this email address. 

    Const DropboxFolder = "C:\!AA\DropBox\" 
    ' A typical value is "C:\Users\Gord\Dropbox\dbStorage\" Note that it must END WITH a backslash 
    ' It is set to the name of the LOCAL folder (ie a folder on the PC running this script) which is synced with dropbox 
    ' (or any internet based file sharing system like Dropbox, Onedrive, GDrive, etc) 

    Const DatabaseCalled = "University and Subject Database" 
    ' The name of the database file without the file extension (ie no .accdb) 

    Const DatabaseExtension = ".accdb" 
    ' The file extension (eg .accdb) 




    ' ----------------------------------------------------------------- 
    ' ----------------------------------------------------------------- 
    ' General constants 
    Const TemporaryFolder = 2 
    Const TAGForINUSE = ".InUse" 
    Const TAGForAVAILABLE = ".Available" 
    Const TAGForOldLocalFile = ".OldFile" 


    Dim WshShell, f, AccessPath, WorkingFolder, DatabaseName 
    Dim FileNameWhenInUse, FileNameWhenAvailable 
    Dim DropBoxInUse, DropBoxAvailable 
    Dim DropboxBackupFolder, DropboxBackupFileName, DropboxDONOTBackupFileName 
    Dim LocalFile, OldLocalFile 
    Dim blnOpenLocalFile 





    ' ----------------------------------------------------------------- 
    ' Use these lines when delivering the code 
    Dim fso 
    Set fso = CreateObject("Scripting.FileSystemObject") 

    ' ----------------------------------------------------------------- 
    ' Use may use these lines when writing the code 
    'Dim fso As Scripting.FileSystemObject 
    'Set fso = New Scripting.FileSystemObject 




    ' ----------------------------------------------------------------- 
    ' About files and folders 

    DatabaseName = DatabaseCalled & DatabaseExtension 

    FileNameWhenInUse = DatabaseName & TAGForINUSE 
    FileNameWhenAvailable = DatabaseName & TAGForAVAILABLE 

    DropBoxInUse = DropboxFolder & FileNameWhenInUse 
    DropBoxAvailable = DropboxFolder & FileNameWhenAvailable 

    DropboxBackupFolder = DropboxFolder & "Backups" 

    WorkingFolder = fso.GetSpecialFolder(TemporaryFolder) & "\" 

    ' eg often: C:\Users\Harvey\AppData\Local\Temp\ 

    LocalFile = WorkingFolder & DatabaseName 
    OldLocalFile = LocalFile & TAGForOldLocalFile 

    blnOpenLocalFile = False 

    ' ----------------------------------------------------------------- 
    ' WARN User 
    ' 
    If vbNo = MsgBox("This will open " & DatabaseName & vbCrLf & _ 
        vbCrLf & _ 
        "DO YOU HAVE ACCESS TO THE WEB?" & vbCrLf & _ 
        vbCrLf & _ 
        "Do not click YES unless you are sure you do as the web is needed to prevent other people from opening the above file while you have it open. " & vbCrLf & _ 
        vbCrLf & _ 
        "NOTE 1: It is OK to loose web access once the file is opened - but others will not be able to use it again until you have web access (and have closed the file)." & vbCrLf & _ 
        vbCrLf & _ 
        "NOTE 2: If you click YES and you do not have web accesss, either you or someone else WILL LOOSE ALL changes made to the file!)", vbYesNo) Then 
     Exit Sub 
    End If 


    ' --------------------------------------------------------------------------------- 
    ' --------------------------------------------------------------------------------- 
    ' 
    ' Main processing - 
    ' The file is only opened if it is available (ie not in use by another person). 
    ' It can also be opened if it is determined that the file was not copied back to the dropbox folder 
    ' but was "accidentally" left in the temp folder 
    ' When it is opened the file is renamed on dropbox to indicate it is unavailable 
    ' 
    If fso.FileExists(DropBoxAvailable) Then 

     Set f = fso.GetFile(DropBoxAvailable) 

     ' This renames the file on dropbox to be "InUse" 
     f.Name = FileNameWhenInUse 

     ' 
     ' Allow dropbox to upload the file ASAP (if possible, force dropbox to sync here) 
     ' 

     WScript.Echo "Copying database file to temp folder..." 
     f.Copy LocalFile 
     Set f = Nothing 

     blnOpenLocalFile = True 

    Else 

     If fso.FileExists(DropBoxInUse) Then 

      If fso.FileExists(LocalFile) Then 

       MsgBox "The database was found locally and will be opened " & vbCrLf & _ 
       vbCrLf & _ 
       "(it had already been previoulsy opened by you, but not written back to the dropbox folder (perhaps a process crashed)." 

       blnOpenLocalFile = True 

      Else 

       MsgBox "The database is currently in use by someone else. Try again later." 
       blnOpenLocalFile = False 

      End If 

     Else 

      MsgBox "The database could not be found on dropbox " & vbCrLf & _ 
      vbCrLf & _ 
      "(Both " & TAGForINUSE & " and " & TAGForAVAILABLE & " versions are missing from dropbox!)." 


      If fso.FileExists(LocalFile) Then 
       MsgBox "A Copy of the file exists locally on your computer. " & vbCrLf & _ 
       vbCrLf & _ 
       "(The file will be opened and written back to dropbox as usual BUT - " & vbCrLf & _ 
       "please email " & SupportEmail & " as this situation should not be arising!)." 

       blnOpenLocalFile = True 

      Else 

       If fso.FileExists(OldLocalFile) Then 

        MsgBox "A backup copy of the local file exists (know as the OldLocalFile)" & vbCrLf & _ 
        vbCrLf & "Email support on " & SupportEmail & vbCrLf & _ 
        "to find out what to do (as this is a really wierd situation)." 

       Else 

        MsgBox "A backup copy of the local file DOES NOT EXIST " & vbCrLf & _ 
        vbCrLf & "Email support on " & SupportEmail & vbCrLf & _ 
        "..but being honest you may be in a really bad pickle, but if you've been taking backups you'll be fine!" 

       End If 

       blnOpenLocalFile = False 

      End If 

     End If 

    End If 


    If blnOpenLocalFile Then 


     ' --------------------------------------------------------------------------------- 
     ' Take a daily backup 
     ' 

     If Not fso.FolderExists(DropboxBackupFolder) Then 
      WScript.Echo "Creating backup folder." 
      fso.CreateFolder DropboxBackupFolder 
     End If 

     DropboxBackupFileName = DropboxBackupFolder & "\" & BuildDateForFile() & DatabaseName 
     DropboxDONOTBackupFileName = DropboxBackupFileName & ".NoBackup" 
     DropboxBackupFileName = DropboxBackupFileName & ".Backup" 

     If Not (fso.FileExists(DropboxBackupFileName)) And Not (fso.FileExists(DropboxDONOTBackupFileName)) Then 

      If vbYes = MsgBox("Do you want to take a daily backup? " & vbCrLf & _ 
           vbCrLf & "(click YES if a lot of work has been done since the last backup was taken. " & vbCrLf & _ 
           " If in doubt click YES)", vbYesNo) Then 

       WScript.Echo "Creating daily backup file." 
       fso.CopyFile LocalFile, DropboxBackupFileName 

      Else 
       ' Create an empty text file to flag no backup is wanted that day 
       WScript.Echo "No daily backup file will be created." 
       fso.CreateTextFile (DropboxDONOTBackupFileName) 

      End If 

     End If 


     ' --------------------------------------------------------------------------------- 
     ' Open the file 
     ' 
     Set WshShell = CreateObject("WScript.Shell") 
     AccessPath = WshShell.RegRead("HKEY_CLASSES_ROOT\Access.MDBFile\shell\Open\command\") 
     AccessPath = Left(AccessPath, InStr(AccessPath, "MSACCESS.EXE") + 12) 

     WScript.Echo "Launching Access and Opening temp database file: " & vbCrLf & LocalFile 

     WshShell.Run AccessPath & " """ & LocalFile & """", 1, True 

     WScript.Echo "Copying temp database file back to Dropbox folder..." 
     fso.CopyFile LocalFile, DropBoxInUse 

     Set f = fso.GetFile(DropBoxInUse) 
     f.Name = FileNameWhenAvailable 
     Set f = Nothing 

     ' Make another copy of the file that was copied to the dropbox folder, then delete the original file 
     ' (This might help stop a bad catastrophe!) 


     WScript.Echo "In Temp Folder: Copying temp database file to be .oldfile" 
     fso.CopyFile LocalFile, OldLocalFile 

     WScript.Echo "In Temp Folder: Deleting temp database file " 
     fso.DeleteFile LocalFile 

    End If 

    Set fso = Nothing 

End Sub 

' Do the work! 
OpenDatabase 
相關問題