• Check if a database is open, if so, close it

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Check if a database is open, if so, close it

    Author
    Topic
    #496774

    I have a batch file that decompiles my backend database every night. Once in a while someone will forget to close their fronted before leaving work and it causes problems. Is there a way to have a batch file check if a database is open and if it is open, close it?

    Viewing 1 reply thread
    Author
    Replies
    • #1470273

      Schultz,

      I’ll make a couple of assumptions here since you didn’t specify.

      1. We’re talking about MS Access.
      2. The individuals are leaving their machines running.

      Some possibilities to investigate:

      A scheduled task on each users machine that would run after normal business hours (could be hard to define) that would run a PowerShell program to check for the Access process and using the Stop-Process cmdlet to shut it down.

      Using PowerShell remoting (would initially have to be setup on each machine) to allow you to check and shutdown via PowerShell program or using the PS ISE.

      If I may ask why are you decompiling your Back end? I could understand compacting but usually all the code (which what benefits from decompiling) is in the Front end so you could move the code out of the BE and eliminate the need to decompile. I used to use a batch file to fetch the latest copy of the FE from the Server on boot of the client insuring the users had the latest version. HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1470280

        Yes, we’re running Microsoft Access 2010, AND all machines are left running all the time. I’m glad you asked the question about the backend. I did not present my problem correctly, it was misleading. I am actually decompiling my frontend, and compacting my backend. The frontend that I decompile is obviously an .accdb which I call GTDevelop. The backend is GTData.mdb. A friend recommended I keep the data in .mdb format so I just took his advice, but the frontend is .accdb. Everytime I push out an update, I publish it as an .accde and rename it DataEntery.accde. Every night a batch file also runs pushing out the .accde to each client so they have the latest version.

        I have rarely used PowerShell, but that shouldn’t be a problem to set up on each client. I’ll do some research on what you suggested. Thanks!

    • #1470330

      Shultz,

      Here’s some PowerShell you can use:

      Code:
      $ErrorActionPreference = 'SilentlyContinue'
      $ Test = Get-Process -Name "MSACCESS" 
      if ($Test -ne $null) {
       Stop-Process -Force -Name "MSACCESS"
      }
      

      Just save the code to a file like Stop-Access.ps1.

      Then setup a scheduled task to fire it up after business hours.

      If you haven’t used PS before you need to setup it up. See Post #2 here.

      To setup the Scheduled Task:
      In the Action Tab -> New
      Program/Script: C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
      Add Arguments: [d]:[your path here]Stop-Access.ps1

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1470358

        OK. Thanks. I’ve been busy on a tech call most the afternoon, will try this tomorrow.

    Viewing 1 reply thread
    Reply To: Check if a database is open, if so, close it

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: