【发布时间】:2014-08-20 16:17:07
【问题描述】:
背景
我开发了许多战术数据捕获工具,所有这些工具都使用相同的前后端分离方法,如下所示:
- 基于 Excel VBA 表单的前端(使用 ADO 连接到后端)
- Access 2007 (accdb) 数据库作为后端
我的偏好是使用 SQL Server 作为后端,但由于我无法解决的限制,这是不可能的。
每个分发的工具都有不同数量的用户同时使用这些工具(介于 10 到 300 多个之间)。我知道 Access 不是提供潜在并发用户数量的理想解决方案,但我再次无法控制。
在使用工具时,用户有时会收到The database has been placed in a state by user 'Admin' on machine '***' that prevents it from being opened or locked. 错误。
考虑到交易量,错误发生的概率约为 0.001%。
我已经阅读了许多关于该主题的文章,其中大部分文章都假设数据库中的对象正在被修改或用户正在输入Design Mode,这应该通过单独的前面来解决和后端。
问题
会出现许多不同类型的查询,包括 SELECT 和 INSERT INTO 语句。用户不直接访问数据库文件,因此没有对象被修改,也没有任何东西被放入Design Mode,为什么用户会遇到这个错误?是因为用户数量太少吗?
我使用相同的方法通过以下方法连接到数据库:
Public Function fGetOrderStatus() As Variant()
Dim oDB As ADODB.Connection
Dim oCM As ADODB.Command
Dim oRS As ADODB.Recordset
On Error GoTo Err:
Set oDB = New ADODB.Connection
oDB.Open gcConn
Set oCM = New ADODB.Command
With oCM
.ActiveConnection = oDB
.CommandText = "SELECT OrderStatusId, OrderStatus FROM ct_elh_OrderStatus WHERE Deleted Is Null"
.CommandType = adCmdText
Set oRS = .Execute
End With
If Not oRS.BOF And Not oRS.EOF Then
fGetOrderStatus = oRS.GetRows()
Else
Erase fGetOrderStatus
End If
oRS.Close
Set oRS = Nothing
oDB.Close
Set oDB = Nothing
Exit Function
Err:
MsgBox ("An unexpected error occurred. Please try again later."), vbCritical, "Error"
End Function
【问题讨论】:
-
他们是否共享 mdb/accdb?
-
@Elias 你是什么意思共享抱歉?他们通过前端访问数据库。
-
他们是否都打开了同一个访问文件,或者他们每个人都获得了自己的原始“模板”副本?
-
他们都通过一个excel前端访问同一个文件
-
很抱歉我错过了您问题中的那部分。谢谢。
标签: sql excel vba ms-access locking