Develop multi-layer database application systems with VB and MTS
(Author: Yu Hua, 2001 at 11:30 on March 14)
MTS (Microsoft Transaction Server) is a middleware product launched by Microsoft for its Windows NT operating system, because it has strong distributed transaction support, security management, resource management and multi-threaded concurrent control, making it on the Windows platform The preferred product of developing large database application systems. Since the MTS blocks the complexity of the underlying implementation, it greatly simplifies the development of such applications, and the programmer can concentrate on the business logic, and thus effectively improve the development efficiency of the software. This article will introduce a method and step of developing multi-layer database application systems with VB and MTS. The step of MTS-based development multi-layer database application is: First step, develop MTS components to provide services, programmers can write MTS components in any language that supports COM, such as VB, VC, Delphi, and Cobol; Step 2 Distribute the MTS component to the MTS package and put the MTS package into the MTS environment; the third step, write the client program call to perform the MTS component in the MTS environment to obtain the service. The detailed development process is as follows: 1. Creating a MTS component In this example we will write a MTS component, run on the intermediate layer application server, which establishes the connection with the database server to complete the teaching teacher information for a course. Start Visual Basic, create a new ActiveX DLL project. Select the project menu, select Microsoft ActiveX Object Library and Microsoft Transaction Sever Type Library in the reference window. Press these two to the project as "OK". From the engineering menu, select the project attribute, change the project name to MTSDemo in the general option.
Thread Module Selects DLL, change the class module name to Course, add the following programs to the universal declaration of the class module: Option Explicit Public Function ListCourses (Byval MCOURSE STRING) AS AdoDb.Recordset On Error Goto Errorhandle Dim Strsql AS String Dim objContext As.ObjectContext Set objContext = GetObjectContext () 'establishing transactional components Dim objADOConn As ADODB.Connection' access to the database using ADO Dim objRS As ADODB.Recordset Set objADOConn = New ADODB.Connection With objADOConn .connectiontimeout = 10 .connectionstring = " Provider = sqloledb.1; userid = sa; initial catalog = dbcourse "" Establish connection with the database through OLEDB .open end with set objrs = new adoDb.recordset strsql = "Select teacher.name, teacher.sex, techer.age, Teacher.edu_level, Teacher.tiltle "strSQL = strSQL &&" From Teacher, TeacherCourse, Courses "strSQL = strSQL &&" Where Teacher.teacher_NO = TeacherCourse.teacher_no and TeacherCourse.course_no = Courses.course_no and Courses.course like ' "&& mCourse &&" '"" LIKE "keyword enables a fuzzy query objrs.open strsql, objadoconn' for database query set listcour ses = ObjRS ObjContext.SetComplte 'if the transaction is successfully completed, the transaction is committed objADOConn.Close Set objADOConn = Nothing Set objRS = Nothing strSQL = ""' Close the database connection, release all objects Exit Function ErrorHandle: ObjContext SetAbort Set ListCourses = Nothing. 'If the transaction fails, the rollback transaction End Function 2. Register all the ActiveX DLL running on the server-side ActiveX DLL should be registered in the MTS, which is done by Transaction Server Explorer. The process is as follows: (1) Creating a package package is a set of components running in the same process, and components in different packages run in the process in the process in which the components in different packages are isolated.