Remote Access Database via three-layer structure model

zhaozj2021-02-16  44

Author: jyu1221 (Tianxong) QQ: 19632995msn: jyu1108@hotmail.comemail: jyu1221@163.net

Everyone knows that if the Access database is placed directly on the server, the client accesses data through file access, so efficiency is too low. In order to solve this problem, access to Access's database is now entered through the three-layer structure model. The Access database here can also be replaced with any relationship database, and the specific structure is as follows:

Client Program | Intermediate Layer | Database | | TCP / IP Application <-> RaccessClient <---------------------> RaccessService <---- -Ado, rdo, DAO -----> Access client interface service program | | | | | | | | -------------- Added a layer on the basis of the original ---------------- |

The client interface uses classes in VB to implement three classes, cconnection, crecordset, ctcpip in the program, where CTCPIP is about accessing the network, and the user is not directly related, CConnection, CRecordset These 2 classes, they are equivalent to adoDb.connection and adoDb.recordset, respectively, ADODB.Recordset. With these two interface classes, you can use most database operations, the specific usage is as follows:

1. Define objects DIM CONN AS New Cconnection 'Adodb.ConnectionDim rs as new crecordset' adoDb.recordset

2. Open the server-side database DIM BCONN AS Booleanbconn = Conn.openConnection ("192.168.1.155", "DSN = TestMDB; driver = {Microsoft Access Driver (* .mdb)}; uid = admin; pwd =;") IF not NOT BCONN THEN MSGBOX CONN.GetLastError () SET CONN = Nothing Exit SUBEND IF

3.1. Open the record set on the server and get data set = conn.openResultSet ("Select * from zdxx") if xi = nothing kilobox "Record set Open error!" EXIT SUBEND IF 'Get the total field NfieldScound = rs.getfieldscount ()

Do uns.GetfieldValueByindex (0) 'The first field subscript starts from 0 Sfield2 = rs.getfieldValueByindex (1) sfield3 = rs.getfieldValueByindex (2) Debug.print Sfield1, Sfield2, Sfield3 RS. MoveNextLooprs.closecordsetset RS = Nothing

3.2. Update Database DIM NROWAFFECTED AS Longdim Strsql AS String Strsql = "Insert Into ZDXX (ZDXX, LKD, Tabstop) Values ​​('Test Content', '120', '1')" "can be in Insert, Update, Delete Any Bok = Conn.execute (Strsql, nrowaffected) if (NOT BOK) THEN MSGBOX CONN.GETLASTERRORSE MSGBOX "Update Record:" & nrowaffected IF

4. Close the object set = NothingSet conn = Nothing

I don't know if you haven't seen it, the access interface and the ADO, RDO, and other access interfaces are similar. It is more similar, if you use ADO, RDO, etc. to access the database, you can easily convert them to this interface. You can upgrade your stand-alone Access application to the server version of the Access database application. Note: This interface does not support the binding method of the control to obtain data, update the data, except for the above, the other database interface is not supported, which can only be accessed by a pure code to access the Access on the server. Server-side programs have been adopted by VC , and readers needed can contact me.

2002.05.17

转载请注明原文地址:https://www.9cbs.com/read-26761.html

New Post(0)