Close MS Access database Using VB.Net

Posted on 2012-08-14
Medium Priority
Last Modified: 2012-08-28
I want to check whether the Access file is open or not in my current application path. If it is open i have to close that Ms Access database using VB.NET?  It has to check in application running path(Current path)

Check for Open database
If Open
Close Access Db
Next step
Question by:keschuster
  • 4
  • 3
LVL 96

Expert Comment

by:Bob Learned
ID: 38296227
I don't understand the context for the question.  Are you talking about a running version of Access with a connection to a database, or a connection within your own application?

Author Comment

ID: 38296916
There is no connection between my VB.net application and MS Access. But Using My application iam replacing files from my server into current Access file path. If Ms Access file is open it should be closed while replacing...I have one button on window form to close Access database.

I have checked in Processes it is showing like MSAccess.exe in Taskmanager. I was tried with below code. But it is not working.

 Dim p() As System.Diagnostics.Process = Process.GetProcesses
        For Each ps In p
            If ps.ProcessName = "MS Access.exe" Then ps.Kill()
LVL 96

Expert Comment

by:Bob Learned
ID: 38296956
You can kill the processes by name, but you have to get the process name correct.  If you start Access, then you can look at the Windows Task Manager "Processes" tab to see what the name is.

There is the Process.GetProcessesByName, which is more efficient, and I believe that the process name for Access is MSACCESS.EXE, and you can confirm that for yourself.
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.


Author Comment

ID: 38297125
Yes the process name is MSACCESS.EXE. I can see only MSACCESS.EXE. i cant find my access db name there in taskmanager.


below code is used for running the file. Like this just i need to close this same file.

System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory & "\PtsTools.accdr")
LVL 96

Expert Comment

by:Bob Learned
ID: 38297169
One approach, if you use Process.Start, is to keep track of the return Process object.

Dim process As Process = Process.Start(fileName)

Open in new window


Author Comment

ID: 38297301
No..at first i open file while downloading updates just i need to close the same file using a button on windows form. l need to kill the access file.
LVL 96

Accepted Solution

Bob Learned earned 1500 total points
ID: 38297394
If you start a process, it should be in the processes list.  Look at the Task Manager "Processes" tab for the process that you started.

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question