简体   繁体   English

MS Access应用程序脱机工作

[英]MS Access Application Work offline

I have an MS Access (2010) application linked to SQL Server (2012) via linked tables. 我有一个通过链接表链接到SQL Server(2012)的MS Access(2010)应用程序。 Is there any way that I can have the users work offline and sync to the server when connected? 有什么方法可以让用户脱机工作并在连接后同步到服务器?

Thanks in advance 提前致谢

In my Opinion there is no simple way to do this. 在我看来,没有简单的方法可以做到这一点。

By design i would mirror the relevant contents of the SQL-Server to a local access-database and let the access program work with this database. 通过设计,我会将SQL Server的相关内容镜像到本地访问数据库,并使访问程序可以与此数据库一起工作。

BUT you need to find a method to sync the offline-data with the SQL-Server. 但是您需要找到一种方法来将脱机数据与SQL Server同步。 That is the tricky part which is highly dependent on the design an purpose of your application. 那是棘手的部分,它在很大程度上取决于应用程序设计的目的。

For Read-Only data in Access from SQL, sure, just have a macro to pull a copy of the SQL tables into the Access database that the user runs to refresh their copy before going off-line. 当然,对于Access from SQL中的只读数据,只需有一个宏即可将SQL表的副本拉到用户运行的Access数据库中,以在离线之前刷新其副本。

It gets much more complicated to sync changes back to the SQL Server if there are multiple users of the same data though. 如果有多个用户使用同一数据,则将更改同步回SQL Server变得更加复杂。 Whose 'data' takes precedence when there are multiple changes to the same record? 当同一记录有多个更改时,谁的“数据”优先?

If your users are adding data only, you could design a holding table to hold the new records and have them kick-off a macro to push those inserts to the SQL table and get a new copy of the SQL table while they are at it. 如果您的用户仅添加数据,则可以设计一个保存表来保存新记录,并让它们启动一个宏以将这些插入内容推入SQL表,并在它们插入时获得SQL表的新副本。 But as said, if they are editing records and multiple users are doing so, this could end in lost data and data corruption very easily. 但是,如上所述,如果他们正在编辑记录并且有多个用户这样做,那么很容易导致数据丢失和数据损坏。

The method to do it is having linked tables to tables on 2 DBs: to the SQL server, and to a local copy Access DB file. 实现此方法的方法是将表链接到2个DB上的表:SQL Server和本地副本Access DB文件。

  1. You copy date from remote to local DB 您将日期从远程复制到本地数据库
  2. Have the user work on local copy 让用户处理本地副本
  3. Synchronize data back to remote DB 将数据同步回远程数据库

If you keep the local tables with the same names, and add some prefix to links to remote table names ("Remote" or "rmt"), You can keep most of you logic: You still process same tables, just linked to a different location. 如果您使用相同的名称保留本地表,并在指向远程表名称的链接(“ Remote”或“ rmt”)中添加一些前缀,则可以保持大多数逻辑:您仍在处理相同的表,只是链接到其他表位置。 Your main issue remains synchronization . 您的主要问题仍然是同步 You need to think of a method, depending on data flow in this system. 您需要考虑一种方法,具体取决于该系统中的数据流。
In this case, general Sync Code would be: 在这种情况下,一般的同步代码为:

For Each tdf In CurrentDb.TableDefs  
    If Left (tdf.name, 3) = "rmt" then   
        CurrentDB.Execuet "DELETE FROM " & tdf.name 
        CurrentDB.Execuet "INSERT INTO " & tdf.name & " SELECT * FROM " & Mid (tdf.name, 4)
    End If
Next tdf

This code deletes all data from remote DB, and inserts data from Local DB instead. 此代码从远程数据库删除所有数据,而是从本地数据库插入数据。 See if this is your synchronization method you need, or you should modify the code to suit your needs. 查看这是否是您需要的同步方法,或者应该修改代码以适合您的需求。 Adding a LastUpdate field to each record in each table (and having it updated at each data modification), could support good synchronization decision making: What records to Delete , and what to Insert , and add the appropriate WHERE clause to the above statements. 向每个表中的每个记录添加LastUpdate字段(并在每次数据修改时对其进行更新)可以支持良好的同步决策:将哪些记录删除 ,将哪些记录插入 ,并在上述语句中添加适当的WHERE子句。
You could also have a General UPDATE SQL Assuming Primary Key of each table is named as the table name, with "ID" prefix : 您还可以将每个表的常规UPDATE SQL 假定主键命名为表名,并带有“ ID”前缀

Dim strSQL As String, srsbl As String, PK As String
Dim tdf As DAO.TableDef, fld As DAO.Field
For Each tdf In CurrentDb.TableDefs  
    if Left (tdf.name, 3) = "rmt" then  
        srsTbl =  Mid (tdf.name, 4) 
        PK = "ID" & srsTbl 
        strSQL = "UPDATE " & tdf.name & " Inner Join " & srsTbl & " ON " &  tdf.name & "." & PK & " = " & srsTbl & "." & PK & " SET "
        For Each fld in tdf.Fields
            if fld.Name <> PK then
                strSQL = strSQL & tdf.name & "." & fld.Name & " = " & srsTbl & "." & fld.Name & ", "                    
            End If
        Next 
        ' Remove Last comma:
        strSQL = Left (strSQL, Len(strSQL) - Len(","))
        ' strSQL = strSQL & " WHERE "...
    End If
Next tdf

This was the technical part. 这是技术部分。 The main issue here is Synchronization method. 这里的主要问题是同步方法。 Search on Data-Base Concurrency control 搜索数据库并发控制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 直接与MS SQL Server 2005一起使用的MS Access 97应用程序 - MS Access 97 application working directly with MS SQL Server 2005 无法与SQL Server连接时可以脱机工作的桌面应用程序 - Desktop application which can work offline when no connectivity with SQL Server 在用户的默认数据库脱机后,如何重新获得对MS SQL Server的访问权限? - How can I regain access to MS SQL Server after default database for a user is taken offline? 脱机时通过MS Access前端访问SQL Server数据库的选项有哪些? - What are my options for accessing an SQL Server database through MS Access front-end while offline MS Access应用程序-将数据存储从Access转换为SQL Server - MS Access Application - Convert data storage from Access to SQL Server 迁移 MS Access 2013 数据库以更好地在家工作解决方案 - Migrating MS Access 2013 DB to better work from home solution 为什么在MS Access中有效的SQL查询在SQL Server中不起作用? - Why does this SQL query that works in MS Access not work in SQL Server? 有没有办法将 MS Access 报告和 forms 转换为任何 web 应用程序框架? - Is there a way to covert MS Access reports and forms to any web application framework? LINQ to ASP.Net应用程序中的MS Access数据库? - LINQ to MS Access database from ASP.Net application? 将基于MS Access的应用程序迁移到SQL Server 2008 - Migrating MS Access based application to SQL Server 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM