Close MS Access database Using VB.Net

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
Who is Participating?
Bob LearnedCommented:
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.
Bob LearnedCommented:
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?
keschusterAuthor Commented:
There is no connection between my 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()
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Bob LearnedCommented:
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.
keschusterAuthor Commented:
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")
Bob LearnedCommented:
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

keschusterAuthor Commented: 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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.