Mobile device Data Access Technology 1

Source: Internet
Author: User

1. Occasionally Connected applications
• "Occasionally Connected Applications" is an application that uses data from a remote database but cannot always access the remote database.
• Although the remote database can be accessed at any time, if you constantly query the rarely changed data (such as the Status List) from the remote database, it may make
Low Efficiency, and occasionally connected applications can be used.
• In these cases, applications can use the data stored in the local database on the client and regularly synchronize data with the remote database.
• In addition to using the local database cache for applications that require occasional connection, you can also consider the number of changes that are rarely changed or changed according to a known schedule
Data is stored in the local database cache.

2. Comparison of Data Synchronization Methods

3. Use sync services to synchronize data

• You can configure the cache to store a single table, table set, or specific records queried from a table.
(For example, a set or a specific record queried from a table, such as a customer with a specific sales representative ).
• Data synchronization between the client database and the server database is performed by Microsoft synchronization.
Services for ADO. Net (Microsoft. synchronization. Data namespace.
4. Synchronization Services API
• Namespace: Microsoft. synchronization. Data
• Microsoft synchronization services for ADO. NET is designed for occasionally connected applications.
• Data can be synchronized between heterogeneous sources through a dual-layer, N-layer, and service-based architecture.
• The synchronization Services API not only copies the database and its architecture, but also provides a group of parts
Synchronize data between the Data Service and the local storage area.
5. Install the sync services API and documentation
• The synchronization Services API does not belong to. NET Framework, but is part of the SQL Server compact 3.5 installation.
(By default, SQL Server compact 3.5 is installed When Visual Studio is installed ).
• To install the synchronization services documentation for local use, you must first install synchronizationy services for ADO. net books online
(Microsoft synchronization services for ADO. net books online.

6. configure data synchronization in the Application
• The local database cache uses SQL Server compact 3.5 to store data locally.
• The existing SQL Server compac t 3.5 database can be used as the local database cache.
• If no local database exists, you can set the "configure data synchronization" dialog box to create a new local database.
• After you add a local database to the application and complete the settings in the configure data synchronization dialog box, you must add the code to the application to start synchronization.
• After the data is synchronized, you must add code to repopulate the tables in the dataset from the local database.
7. "configure data synchronization" dialog box
• The "configure data synchronization" dialog box can only be used to configure Microsoft synchronization services for ADO. net for the download solution.
• In other words, After configuring data synchronization in the "configure data synchronization" dialog box, calling the synchronize () method will only update the local database using the changes found on the remote database.
• Changes made to data in the local database will not be uploaded to the remote database.
• After configuring data synchronization in the "configure data synchronization" dialog box, you can enable upload during synchronization programmatically (bidirectional synchronization ).
8. Configure Data Synchronization
• Server connection: provides data connections to remote databases.
• Client connection: provides data connection to the local database or creates a new database on the client.
• "Cached tables": select the tables you want to use in your application from a remote connection.
• For each table to be added to the local database, select the columns required for coordinated modification and the table used to store the deletion items.
In addition to the tables with deleted records, each table also needs to track new records and tables with deleted records. In addition, each table also needs to track new records and
The specified column of the modified record.

9. Additional items required for remote database

10. enable synchronization
• After "local database cache" is added and configuration information is provided in the "configure data synchronization" dialog box, you must add code to your application to synchronize the local database first.
Local Database and remote database.
• You can call the synchronize method of syncagent to start synchronization.
• You can then call the tableadapter. Fill Method to load the data table of the dataset with the updated data in the local database.
11. Synchronization direction
• Only download Synchronization
• Upload synchronization only
• Snapshot Synchronization
• Bidirectional Synchronization
12. tables that cannot be cached
• Do not use tables with the user's default architecture.
• Tables with no primary keys defined.
• Tables with names exceeding 118 characters.
• Tables that contain columns not supported by SQL Server compact 3.5.

13. instance: Create occasionally connected applications

A) create a form application project: refactorocswalkthrough

B) Right-click the project and add a new project:

C) Click Add.

D) Click Add.

E) Click OK.

F) Click OK.

G) click Next.

H) Click "finish". The project structure is as follows:

I) drag the data source to the form and add the synchronization button

J) modify the background code:

View code

Private void customersbindingnavigatorsaveitem_click (Object sender, eventargs e) {This. validate (); this. customersbindingsource. endedit (); this. tableadaptermanager. updateall (this. northwinddataset);} private void form1_load (Object sender, eventargs e) {// todo: This line of code loads data to the table "northwinddataset. in MERs. You can move or delete it as needed. This. customerstableadapter. fill (this. northwinddataset. customers);} private void synchronizebutton_click (Object sender, eventargs e) {northwindcachesyncagent syncagent = new northwindcachesyncagent (); Microsoft. synchronization. data. syncstatistics syncstats = syncagent. synchronize (); this. customerstableadapter. fill (this. northwinddataset. customers); MessageBox. show (syncstats. totalchangesdownloaded. tostring ());}

In this way, the remote database and local database can be synchronized.

 

To be continued, please wait...

Reprinted please indicate the source: http://www.cnblogs.com/refactor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.