强制所有用户从2010 Access后端数据库断开连接 [英] Force all users to disconnect from 2010 Access backend database
问题描述
我们有多用户前端/后端MS Access 2010应用程序.我们添加了一个过程,当我们要在后端进行压缩和修复之类的工作时,它将关闭远程前端.这是基于计时器的对表字段的检查,如果具有一定的值,则将关闭应用程序.
We have multi user frontend/backend MS Access 2010 application. We added a process that will close remote frontends when we want to do work on backend such as compact and repair. This is timer based check on table field that if has certain value will close the application.
我做了两次检查,看用户是否连接到数据库:
I do two checks to see if users are connected to database:
-
我具有登录/注销过程,可以看到谁仍在登录(基于其表单,因此很容易出错,例如,他们关闭了表单,但前端仍处于打开状态).
i have login/logout process and can see who is still logged in (its form based so is fallible eg they close form but frontend is still open).
我使用.ldb文件查看器查看是否仍然有连接
i used .ldb file viewer to see if anything is still connected
两个问题:
-
如果无法通过ldb查看器查看,是否有可能存在与支持的连接?
is there any possibility that a connection to backed could exist if it wasn't viewable with ldb viewer?
是否有100%可靠的防弹方式来强制断开所有与后端的连接?
is there any bullet proof 100% certain way to forcefully disconnect all connections from backend?
推荐答案
"我进行了两次检查,看是否用户已连接到数据库"
如果您需要专门打开数据库,则可以跳过其他检查,而只是检查是否可以打开.
If you need to open the db exclusively, you can skip the other checks and just check whether you can do it.
Public Function CheckExclusive(ByVal pFullPath As String) As Boolean
Dim blnReturn As Boolean
Dim cn As Object
Dim strConnection As String
On Error GoTo ErrorHandler
strConnection = "Provider=" & _
CurrentProject.Connection.Provider & _
";Data Source=" & pFullPath & ";"
Set cn = CreateObject("ADODB.Connection")
cn.Mode = 12& ' adModeShareExclusive '
cn.Open strConnection
blnReturn = True
cn.Close
ExitHere:
On Error Resume Next
Set cn = Nothing
On Error GoTo 0
CheckExclusive = blnReturn
Exit Function
ErrorHandler:
blnReturn = False
GoTo ExitHere
End Function
然后使用数据库文件的完整路径调用该函数.
Then call that function with the full path to your db file.
If CheckExclusive("C:\SomeFolder\YourDb.mdb") = True Then
' do what you need here which requires exclusive access: '
' make backup; compact; whatever '
End If
这篇关于强制所有用户从2010 Access后端数据库断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!