C#.net Large Enterprise Information System integration rapid development Platform 4.2 version-large software system client data synchronization problem solving

Source: Internet
Author: User
Tags dotnet

As a complete overall information solution needs to be strong enough to function, these functions are relatively independent, and interdependent. When there is a need for such a function can be taken out at any time, the appropriate modification can meet the requirements. Only in this way can the rapid development of various information systems to meet the needs of a variety of customers.

The main problems to be solved in synchronizing data are:

01: National Large-scale group of information transformation project will involve a lot of branch offices of the client needs to synchronize the various needs of the data, this has exceeded the limit of the human can handle well.
02: A very long time, often due to the particularity of the business will have the need to work offline, network failure, network bandwidth is not ideal can be offline processing workflow needs.
03: Also due to network security reasons, work special reasons, must have some data to be processed in the local network, and then through the special line, such as the timing of uploading business data.
04: Handheld mobile devices, because the work environment does not have real-time internet conditions, may also need to deal with the data in offline conditions, connected to the network when the data uploaded to the headquarters.
05: There is a need to synchronize from a large database to a desktop database, for example, the server is SQL Servers and the client is SQLite.
06: There may also be data synchronization between the server and the server, such as the production of the main database synchronization to the statistical database, synchronization into the query database.
07: The Headquarters database on the server can be large, and each dot may only need to synchronize some of the databases, even the data portions of the specially restricted SQL statements need to be synchronized.
08: If you need to synchronize the data more than a long, due to network bandwidth, server stability considerations, need to provide batch access to data, you can obtain data in batches.
09: When the table structure is changed, there is an increase, there is a reduction, there is a change is, do not have a problem failure, you can smoothly upgrade, can smoothly synchronize data.
10: If there are tens of thousands of information terminals, if there is no data on the need for any SQL statement query, reduce the central database query pressure.
11: Access to the library, allow synchronized tables for permission control, to prevent unauthorized access to the data should not be seen.
12: The security of the interface calls, how to prevent malicious calls, etc., to an open interface, these need to consider the risk.
13: Upgrade synchronization can also be flexible, can execute SQL statements, can write C # logic control code.
14: The Synchronizer can be carried out in the background without affecting the primary business functions and does not affect the business operations.
15: Code Concise, good maintenance, good debugging, good improvement, good to quickly increase the synchronization of additional data tables.

The reference code is as follows:

-----------------------------------------------------------------//All rights Reserved, Copyright (C) 2015, Hairihan TECH, Ltd.//-----------------------------------------------------------------using system;using System.collections.specialized;using system.data;using system.net;using system.text;using Newtonsoft.Json;    namespace dotnet.win{using Dotnet.business;    Using Dotnet.utilities; <summary>///Data synchronization class///</summary> public partial class Synchronous {//&LT;SUMMARY&G        T        Tool classes for Remote Data synchronization///</summary>//<param name= "Fromdatabase" > which database from the server gets data </param>        <param name= "TableName" > Synchronize which table </param>///<param Name= "Primarykeys" > What is the primary key of the table </param> <param name= "ModifiedOn" > Sync update Time </param>//<param name= "Todatabasedbtype" > Sync to local what type of data Coorey </param>//<param name= "DbConnection" > How is the target database connection synchronized? </param>///<returns> affects the number of rows </returns> public static int synchronoustable (string fromdatabase, string tableName, str Ing[] Primarykeys, DateTime?            ModifiedOn, Currentdbtype Todatabasedbtype, string dbConnection) {int result = 0;            Input parameter Check if (Primarykeys = = null) {return result;            } int toplimit = 200;            DataTable datatable = null;            Idbhelper dbhelper = null;            DBHelper = Dbhelperfactory.gethelper (Todatabasedbtype, dbConnection);            Sqlbuilder Sqlbuilder = new Sqlbuilder (dbhelper); while (Toplimit = =) {String url = basesysteminfo.webhost + "Webapiv42/api/synchronous/getto                Plimittable ";                WebClient WebClient = new WebClient ();                NameValueCollection postvalues = new NameValueCollection ();                Postvalues.add ("UserInfo", BaseSystemInfo.UserInfo.Serialize ()); Postvalues.add("Systemcode", Basesysteminfo.systemcode);                Postvalues.add ("SecurityKey", Basesysteminfo.securitykey);                Postvalues.add ("DataBase", fromdatabase);                Postvalues.add ("TableName", tableName);                Postvalues.add ("Toplimit", toplimit.tostring ());                Postvalues.add ("ModifiedOn", ModifiedOn.Value.ToString (Basesysteminfo.datetimeformat));                Send post data to the server byte[] Responsearray = webclient.uploadvalues (URL, postvalues);                String response = Encoding.UTF8.GetString (Responsearray); if (!string. IsNullOrEmpty (response)) {datatable = (DataTable) Jsonconvert.deserializeobject (response                , typeof (DataTable));                } int r = 0;                The log of the error needs to be saved, so there is a problem to find out why.                    for (r = 0; r < DataTable.Rows.Count; r++) {//delete data first, modified, new, deleted and added to handle, the problem is simplified. DbhelpEr. ExecuteNonQuery ("DELETE from" + TableName + "WHERE" + primaryKey + "= '" + Datatable.rows[r][primarykey].                    ToString () + "'");                    Sqlbuilder.begindelete (TableName); for (int i = 0; i < primarykeys.length; i++) {String PrimaryKey = PrimaryKey                        S[i]; if (string. Isnullorwhitespace (PrimaryKey)) {Sqlbuilder.setwhere (PrimaryKey, Datata ble. Rows[r][primarykey].                        ToString ());                    }} sqlbuilder.enddelete ();                    Then insert the data Sqlbuilder.begininsert (tableName); for (int i = 0; i < DataTable.Columns.Count; i++) {//This is a perfect place to judge whether the field exists in the target table.                        The Sqlbuilder.setvalue (Datatable.columns[i]. ColumnName, Datatable.rows[r][datatable.columns[i].                    ColumnName]);          }          Sqlbuilder.endinsert (); if (DateTime.Parse (Datatable.rows[r][basebusinesslogic.fieldmodifiedon). ToString ()) > Modifiedon.value) {modifiedon = DateTime.Parse (datatable.rows[ R][basebusinesslogic.fieldmodifiedon].                    ToString ());                } result++;            } toplimit = DataTable.Rows.Count;        } return result; }    }}

C#.net Large Enterprise Information System integration rapid development Platform 4.2 version-large software system client data synchronization problem solving

Related Article

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.