MTS development multi-layer database application system

zhaozj2021-02-11  213

MTS is a middleware product launched by Microsoft for its Windows NT operating system, because it has a strong distributed transaction support, security management, resource management and multi-threaded control, making it a large database application system on a Windows platform The preferred product.

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. Create a MTS component In this case we will write an 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. The thread module selects a division thread DLL, change the class module name to Course, and add the following programs to the universal declaration of the class module:

Option expedition

Public Function ListCourses (Byval MCOURS String) as adoDb.recordset

ON Error Goto Errorhandle

DIM STRSQL AS STRING

Dim objcontext as.objectContext

Set objcontext = getObjectContext ()

'Establish a transactional component

Dim objadoconn as adoDb.connection

'Using ADO Access Database

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, Coursees"

strsql = strsql && "where teacher.teacher_no = teachercourse.teacher_no

And teachercourse.course_no = coursees.course_no

And coursetes.course like '"&& mcours &&"' "'" like "keywords to achieve a fuzzy query

Objrs.open strsql, objadoconn

'Database query

Set listCours = ObJRS

Objcontext.setComplte

'If the transaction is successfully completed, then the transaction is submitted.

Objadoconn.close

Set objadoconn = Nothing

Set objrs = Nothing

strsql = "" "

'Turn off the database connection, release all objects

EXIT FUNCTION

ErrorHandle:

Objcontext. Setabort

Set listCours = Nothing

'If the transaction fails, roll back the transaction

END FUNCTION

2. Registering the MTS Components All ActiveX DLLs running on the server should be registered in the MTS, which is done by Transaction Server Explorer. The process is as follows:

(1) Creating a package

The package is a set of components running in the same process, and components in different packages are running in the process in which the components in different packages are isolated. When creating a package, developers should assign components of the shared resource to the same package; consider the resources shared by each component in the package, you can share "expensive" resources (such as a specific database) The connection) component is compiled.

(2) Add components to the package

Select the Component folder in the package where you want to install the component, click the Install New Component button to find the newly generated MTSDemo.dll file when prompted to add a file.

3. Write a client program to create a standard EXE project. Select the project menu, then select the reference, select the MTSDemo just created in the reference window to join the project.

Add the following to the form:

Name title

Tag Label1 Please enter the course name:

Text box txtcourse

Command button CMDOK query

Data grid DGRESULT

Add the following procedures to the universal declaration:

Private sub cmdok_click ()

Dim RsResult As Adodb.Recordset

DIM Objmts as Object

DIM MCOURSE STRING

MCOURSE = TRIM (TXTCOURSE.TEXT)

Set objmts = createObject (mtsdemo.course)

SET RSRESULT = Objcourse.listCourses (MCOURSE)

IF rResult.eof then

Msgbox ("Records without satisfaction!")

EXIT SUB

END IF

Set DgResult.dataSource = rsResult

DgResult.columns (0) .caption = "Name"

DgResult.columns (1) .caption = "Sex"

DgResult.columns (2) .caption = "age"

DgResult.columns (3) .caption = "Education"

DgResult.columns (4) .caption = "title"

DgResult.refresh

Set objmts = Nothing

End Sub

4. Run the client first compile the written client program, then find a new package in Microsoft Management Console, right click to select the export, export it to C: / Program file / packages, in this file The Client of the clip automatically generates the client installer of MTSDemo. Run the setup.exe file under the client, and then install the client program. The above code from: the source code database (SourceDataBase) Current Version: 1.0.392 Author: Shawls profile: Http://Shawls.Yeah.Net E-Mail: ShawFile@163.Net QQ: 9181729

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

New Post(0)