阻止提交对 Microsoft Access 数据库的更改

发布于 2024-09-06 00:02:18 字数 73 浏览 6 评论 0原文

有没有办法编写一个在将更改提交到 Access DB 之前运行的挂钩?如果特定进程当前正在查询数据库,我正在寻找一种阻止更改的方法。

Is there a way to write a hook that will run before changes are committed to an Access DB? I'm looking for a way to block changes if a specific process is currently querying the DB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不咬妳我踢妳 2024-09-13 00:02:18

你没有给我们提供太多可以使用的信息。您可以调整类似 创建并使用灵活的自动编号字段,因此特定流程首先以独占方式打开一个表?然后,任何其他可能更改数据的操作都必须等待,直到它们可以锁定同一个表。

具体流程是什么?您是否有方法确定何时/是否从数据库读取数据?

如果特定进程位于数据库外部,例如使用 ADO 获取数据的 Web 服务器 ASP 代码,您可以查看 ADO 连接模式和 IsolationLevel 属性是否有帮助。

更新:我使用表单来试验 ADO 连接的 adModeShareDenyWrite Mode 属性。当表单打开时,其他用户可以打开数据库,但不能进行任何更改。但是,如果在表单尝试打开连接时另一个用户已经打开了数据库,则会触发错误。

也许您的部署脚本可以尝试打开 adModeShareDenyWrite 连接,并在出现错误时退出。

Option Compare Database
Option Explicit
Dim cn As ADODB.Connection

Private Sub Form_Close()
    If Not (cn Is Nothing) Then
        cn.Close
        Set cn = Nothing
    End If
End Sub

Private Sub Form_Load()
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=\\Cmpq\export\Access\backend\links2003.mdb;" & _
        "User Id=admin;Password=;"
    cn.Mode = adModeShareDenyWrite
    cn.Open
End Sub

You didn't give us much information to work with. Can you adapt something like Create and Use Flexible AutoNumber Fields so specific process first opens a table exclusively? Then any other operations which might change data would have to wait until they can lock that same table.

What is specific process? Do you have a method to determine when/if it is reading data from your database?

If specific process is external to the database, like web server ASP code which uses ADO to fetch data, you could see whether the ADO connection Mode and IsolationLevel properties can help.

Update: I used a form to experiment with the adModeShareDenyWrite Mode property for an ADO connection. While the form is open, other users can open the database, but not make any changes. However, if another user already has the db open when the form attempts to open the connection, it triggers an error.

Perhaps your deployment script could attempt to open a adModeShareDenyWrite connection, and bail out on error.

Option Compare Database
Option Explicit
Dim cn As ADODB.Connection

Private Sub Form_Close()
    If Not (cn Is Nothing) Then
        cn.Close
        Set cn = Nothing
    End If
End Sub

Private Sub Form_Load()
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=\\Cmpq\export\Access\backend\links2003.mdb;" & _
        "User Id=admin;Password=;"
    cn.Mode = adModeShareDenyWrite
    cn.Open
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文