Instance Development
A household appliances chain has a headquarters and many branches, headquarters and branches and branches often need to carry out a variety of information inquiries (such as: Commodity Day price list, store sales status and inventory information, etc.), the organization set up a distributed Database query system, It can realize the sharing of Headquarters and store information, so as to facilitate the unified management.
3.1 System Design
3.1.1 System structure diagram
System Structure 2 shows:
Figure 2 System Structure diagram
Headquarters and branches are equipped with a fixed IP server, the other computers through the hub and the server connected to the headquarters and the branch of the server through the communication network connected together. Network Management Alliance www.bitsCN.com
3.1.2 System Implementation Steps
Network Management net Bitscn_com
The implementation of the system is divided into three main steps. First, design the database for Headquarters and stores. Because of the large amount of data, SQL Server is used to create a sales and inventory database for each branch, as well as an employee database for the headquarters, an inventory database for the entire chain, and a credit card customer database . and supplier Information database . Second, a dynamic-link library (DLL) that provides a database service (dbserver) is needed to set up some of the services (e.g., publishing and fetching of remote objects) and functions (such as: Queries for local offsite data tables, remote creation and deletion of data tables, Joins and merges between tables, etc.) are placed in the DLL, and each branch needs to use this DLL to make calls to some services and functions at query time. Finally, the client query interface is developed according to the actual needs. Network Management Alliance www.bitsCN.com
3.2 Key technologies for system implementation
3.2.1 Release and acquisition of remote objects
The first thing to do after the system runs is to publish the local remote object and get the remote objects published by the other stores. When you publish a remote object, you first set up a network port number, then create and register a channel, and finally publish the server-side activation object. Servers in other venues can easily get the published remote objects based on the IP address and network port number. The key code for implementing remote object publishing and fetching is as follows:
Publication of remote objects:
54com.cn
Create a channel instance, port for the specified network port number TcpChannel mychannel= new TcpChannel (Int32.Parse (port)); Registration channel ChannelServices.RegisterChannel (MYCHANNEL); Publish the server-side Activation Object RemotingConfiguration.RegisterWellKnownServiceType (typeof (DBServer), "STORE", Wellknownobjectmode.singleton); Remote Object acquisition://Based on IP address and port number of the corresponding remote object try {mydbserver= (dbserver) Activator.GetObject (typeof (DBServer), "tcp://" +ip+ ":" +p+ " /store "); }//catch exception catch (NullReferenceException nullexp) {MessageBox.Show ("The specified URL address is unreachable" + nullexp.message);} catch (RemotingException remexp) {MessageBox.Show ("specifies that the obtained object definition is not correct" + remexp.message);} Network Management Net bitscn_com
Access to the 3.2.2 database
Access database , you can easily connect database , import data from the data source into the DataSet object, and in the DataSet object, you can perform various operations on the data table, And the DataSet object itself can also be passed remotely. This provides great convenience for developing distributed database system. Implement accesses is as follows:
Establish a connection to the database string sqlconn = "Initial catalog=store;data source=localhost; Userid=sa; password=; "; SqlConnection conn= New SqlConnection (sqlconn); Conn.Open ();//Open database //import data from data source into DataSet object try{DataSet ds = new DataSet (); DataTable dt=new DataTable ("Result"); SqlDataAdapter Adapter=new SqlDataAdapter (); SqlCommand mysqldatasetcmd =new SqlCommand (cmdstring,conn);//cmdstring for the command to be executed. Selectcommand= Mysqldatasetcmd; Adapter. Fill (DT); Ds. Tables.add (DT); } finally {conn.close ();//close connection to database }
3.2.3 Query com
Queries in Distributed database systems generally fall into three categories: local queries, remote queries, and federated queries. Local query and centralized database query is no different, for remote query, as long as the remote object, call query function can be easily implemented, the most complex is the joint query, involving multi-site data query, table remote creation, transfer, connection, merge and other technologies. The following example describes the implementation of a federated query.
The second chain to inquire about the third, the fourth chain in the near the supply of all Beijing suppliers of air-conditioning inventory information for the transfer, can be achieved by the following steps. First, get the remote objects published by the headquarters and the third and fourth chain stores. Next, create a temporary data table T1 from the remote object at Headquarters, and store all the supplier information from Beijing in the T1 table (each branch has only the supplier name, not the location, only the headquarters have the supplier details), and then save the T1 table to the third and fourth chain stores. The T1 table is then connected to the inventory table of two stores to find out all the air-conditioning inventory information (such as air-conditioning name, model number, quantity, price, etc.) supplied by all Beijing suppliers, and return the connection results T2 and T3 data sheet to the second chain store. Finally, the T2 and T3 two tables are merged and displayed using the DataGrid control. The above implementation, including the data table between the different sites copy, transfer, connection, and so on, some of the functions used (such as: remote creation of data tables, the remote connection between table and table, merge, etc.) are placed in the DLL, can be easily called.
. NET Remoting Distributed Development Example ideas (RPM)