2

我有一个项目,我要将 MS Access DB 与 MySQL DB 同步,我想知道从/向 MS Access DB 读取/写入的最佳方法,因为它会在我执行此操作时锁定 DB。(会有其他应用程序读取/写入同一个 Access DB,所以我想尽量减少锁定它的时间)。

我选择的语言有区别吗?我最习惯使用 C# 和 .NET 编写应用程序。

有没有更经验丰富的建议/经验?

4

3 回答 3

3

将您的应用程序将专门用于查找目的的查询存储在 Access DB 中,并在查询属性中存储为 ReadOnly。然后让您的应用程序查询那些 ReadOnly 查询,这将防止不必要的锁定。

在应用程序中保持更新和插入 SQL 语句的简短和简单也会在一定程度上限制锁定时间。

于 2012-12-03T15:23:08.823 回答
1

I dont think the language matters much - you can use C# or VB in a .NET environment. Are you planning a real-time synchronization or an off-hours (lets say daily) synchronization of the two databases?

One approach for the synchronization would be to do a data dump of the tables to a text file, load them into properly indexed tables and then find updated records (using data access queries) and find new records (with an outer join) and append them to the datastore.

于 2012-12-03T15:44:39.697 回答
1
  1. 如果您的表不包含主键。添加一个,我们将其命名为“Id”

  2. 创建表“sync_log”以存储更改。

    • “SQL”的一列适用于目标数据库。
    • 此“SQL”的执行状态的一列。(待定,已完成)
    • 此“SQL”的时间一列,然后您可以按原始顺序将 SQL 应用到目标数据库。
  3. 为创建、更新、删除创建触发器

    crate: 创建一行时,您的触发器会将以下行插入另一个表“sync_log”

    “插入表 T 值(CA、CB、CC、CD)”

    删除: 创建一行时,您的触发器会将以下行插入另一个表“sync_log”

    “从 Id = 99 的表 T 中删除”

    update:类似,也是通过主键“Id”识别目标行

  4. 让您的应用轮询表“sync_log”,将新的“待处理”SQL 应用到目标数据库,然后将“sync_log”中的 SQL 状态更新为“已完成”。

这是一种方式同步,另一种方式同步类似。

if (你正在使用 Microsoft Access 项目) then {http://office.microsoft.com/en-au/access-help/create-a-trigger-adp-HP003085415.aspx } else { Access 宏事件类似于触发器. http://blogs.office.com/b/microsoft-access/archive/2009/08/13/access-2010-data-macros-similar-to-triggers.aspx }

于 2012-12-07T16:03:16.103 回答