25. Components and Microsoft Distributed Trading Coordinator
Component service overview
Microsoft Distributed Trading Coordinator
Summary of this chapter
This chapter will learn the Microsoft Distributed Transaction Coordinator, MS DTC, which allows a database transaction to access multiple data sources and ensure the integrity of the data. You will see MS DTC in this chapter that many types of applications must be used by MS DTC.
MS DTC is a part of component service. The component service is derived from Microsoft Windows NT service and is a collection of buildings in Windows 2000 products and technology. Component services include Component Object Model (COM), Distributed COM (DCOM), Microsoft Transaction Server, Microsoft Internet Information Server, and Microsoft Message Queue Server. In Windows 2000 components, COM and DCOM technology have new levels, so call COM . Com applications and other system services make up the project of Windows 2000 Components. Before you officially introduce MS DTC, we will briefly introduce component services.
Component Services is a tool that is combined by several different products, using a unified Microsoft Management Console (MMC) management window. Component service is an embedded management unit of the main control station, including: COM Application Services MS DTC Event Checker Service System Services Microsoft Message 伫 Legal To Execute Component Service Management Tools, press Start → Program Set → System Management Tool Then select the component service to start the main control station, as shown in Figure 25-1.
Figure 25-1 "Component Service" main control station
COM Application Service COM Application Service refers to an application developed using Microsoft's COM specifications. COM is an extension of the COM module. COM is the development of decentralized applications, develops to COM , making security and column components easier to develop on applications. You can set your COM application element in component service MMC. Enter your COM application according to the following steps (Figure 25-2): Expand Component Services → Computer → My Computer → COM Application On the screen you will see all registered COM applications. After expanding your COM application folder, you can choose to enter these applications.
Figure 25-2 Component Services Main Control Table View CoM Application
The MS DTC is the MS DTC's data clip below the component service main control platform, COM application folder. We will discuss MS DTC in detail in the next section. This section will not be described. The event checker service This service tool is developed by the Window NT's event view tool. The Windows 2000 event checker service is the same as the event review in Windows NT, allowing you to enter the event record access data. All applications, security materials, system errors, and information materials are stored in event records, we must check these records at any time. You can find an event check folder in the window of the component service, expand this data clip (as shown in Figure 25-3), and click the event record that you want to see, you can view the information. Figure 25-3 Event View data clip window
The system service system service tool is developed by the Windows NT service tool. System Services allows you to view all the service tools installed on your system. When you expand the service folder, you can view the system service (Figure 25-4).
Figure 25-4 Expanding the service data clamp checking system service tool.
If you want to start or stop the service tool, click the Tool button to click the right button to select the option to perform in the flash function table (Figure 25-5).
Figure 25-5 Fast display function
If you want to view or modify the properties of the service tool, select the properties within the graphical function table in the figure, and call the properties window of the service tool (as shown in Figure 25-6).
Figure 25-6 Window of the "General" tab in service properties
In the general window, you can change the service tool setting content, or stop or pause the service tool. Other tabs allow the way to change the service to log in to Windows 2000. Attributes are important to service tools. In this setting, you can choose whether the system is automatically started to start the service tool or change the account used by SQL Server and MS DTC. In addition, it is also possible to specify what action when the service tool is problematic. In this window you can also view dependence between services. Microsoft Messages Although the service component MMC does not display Microsoft message 伫 column (MSMQ), because it also uses the MS DTC for external transactions, it can be considered as part of the component service. Microsoft Messages Allow messages to deliver transactions or non-trading messages between different applications or intercomminal. The application utilizes a message to deliver a durable message between the servo, Durable Message. Tuzui message means that this message will not disappear due to system failure (if it is faulty due to power failure). Suppose the system suddenly power out, when the system reply, MSMQ will continue to perform a message. Microsoft Messages are sent to deliver messages with storage and transfer (STORE-AND-Forward). This method is still stored in the column even when there is a problem in the network. The other functions of the message is as follows: You can send a message if you want to use the message column component to deliver a message, it doesn't mean you have to connect; in addition, the message can be routed so that you can establish a link between different communications. Dynamic 伫伫 Management: Do not restart your message when adding or changing. Alternative message priority sequence: Message 伫 伫 can be sorted in priority, and you can set first-to-transfer high priority order. Can support the cluster: Message can detect clusters, support active / active and active / passive (Active / Passive) Cluster. Can be integrated with the Active Directory directory: Message column can be used in the directory service in Active Directory. Can communicate with MSMQ 1: Message 伫 can communicate with MSMQ 1, MSMQ 1 is a message. Can be integrated with Windows 2000 security features: the security features that can be used to enhance Windows 2000. Message Backup and Reply: You can back up your message, you can also reply to the message when the system has problems.
Use MMC to manage: Now the information is the same as many other management tools, both in the main control station. As you can see, Microsoft Message is a lot of functions. However, this chapter will focus on the transaction messaging components in the message column, which is MS DTC. The Microsoft Distributed Trading Coordinator has previously mentioned that MS DTC is part of the Windows 2000 component service. (MS DTC This concept already exists in SQL Server 7.) The component service also contains COM . COM is used for non-transactional communication needs, while MS DTC is used to have transaction-based message communication needs. MS DTC is mainly used to handle decentralized transactions. The so-called decentralized transactions are transactions across two or more libraries, which can be placed in different computer systems. In the same database, the transaction of different data sheets is unable to be called decentralized transactions. On the same system, the front-end transactions between the database and the database can be treated with general (non-scattered); however, SQL will still be dealt with in a decentralized transaction. MS DTC Overview When a transaction contains many different sources of information, it is necessary to coordinate the application of these information. The importance of coordination is that the transaction must be unable to do. In other words, the modification of the information is not all executed, that is, all do not execute. If a transaction is completed, some failed, it will cause the transaction logic without consistency, and the data can be lost. MS DTC performs two phaedes of transaction recognition (TW-PHASE commit) confirms the transaction logic. Two-stage trading recognition has been technically reform in recent years, which is not new technology, nor SQL Server is unique. In fact, due to both SQL Server and Oracle's two databases supported two-stage transactions recognized models and ODBC, the two data wares can also be used to deal with different transactions. Two stages of the two-stage transaction recognition are: preparation stage and the accreditation phase. In the application, the MS DTC is initialized in the application, the MS DTC execution two-stage transaction recognition is performed. MS DTC on a SQL Server, a decentralized transaction is processed with MS DTC on another system. The components of the two transactions recognized in the MS DTC are called the resource administrator. When you perform an approved (Commit) instruction, the MS DTC notifies the resource administrator to begin the preparation stage. The first phase (that is, the preparation phase) will perform the actions required for all approved, including the buffer and write transaction record files. The steps performed at this stage are similar, so the only difference is here, SQL Server will not really recognize the transaction, nor will the resource used to use the resource used to lock. When all the pre-action of all recognized transactions are completed, the resource administrator transmits the signal to the transaction administrator. When all the resource administrators have sent successful signals, they entered the accreditation phase. The accreditation phase is carried out in a decentralized system. At this stage, if all the resource administrators pass the success signal, the application terminal accepts a message that the recognized success; if one of the resource administrators pass the failure signal, the ROLLBACK instruction will be transmitted to each A resource administrator, at this time, the application is a message that the recognized failed. Recovery instructions are also performed when the system trading time is too long. When a system within a system fails, all other related systems in a decentralized transaction will also perform recovery instructions.
MS DTC Usage Example In this section, let's refer to the example of using the MS DTC in two real life, you can see the importance of MS DTC in decentralized transactions, and how the system handles unsuccessful transactions. Real World Bank transactions are in the bank's remittance transactions. When the customer wants to exchange a bank account to the B bank account 2, the bank's computer has to implement two transactions: put the money from the account 1 , Then add money to your account 2.
Let's talk about how to make money. If the two accounts are in the same bank, the system can update the information of a database; however, if the two accounts are different banks, they have to start remote transactions. This transaction has to handle the system. Two trading steps, transactions can be performed in one of two systems, or on the third system (user end system).
When the member performs the transaction on the user-end computer, the application starts calling SQL execution tasks, and SQL will begin to perform the following items:
Update system A, deduct the account 1 of the account 1, to add the amount to the account 2 to approve the transaction
In the case where each system is functioning is completely normal, such a mode of operation is acceptable, but it is not a fully safe mode of operation. For example, if there is only one system to complete the transaction, another system transaction failed. The following is a case where the transaction step of system A failed, and the transaction of system B cannot be executed, and the transfer failed. The trading step of system A is successful, but the transaction of system B failed, the amount disappears. Such trading is certainly not to happen. So the following trading steps are just a safe trading process.
Update system A, deduct the amount of the account 1 to the update system B, and add the amount to the account 2 as a group of trading programs to be approved, all approved or all unrecognizable.
MS DTC allows you to recognize the decentralized transaction to be approved, that is, you can recognize a group of trading steps, if one of the trading steps have issued a problem, so that the above-mentioned error.
The application of real world e-commerce applications often requires simultaneous processing of large quantities of online trading behavior, so numerous systems should be required to cope with huge trading volume. If a company uses only one computer system to cope with all transactions, it is not suitable. The following is a concern of a company may encounter: a system load is too heavy: each computer and system have a certain amount of load, too many transactions The amount is easy to cause a single computer and system overload. Business Logic: In terms of business logic, put different functionality is more reasonable on different systems. For example, the user data can be placed in one system, and the product information is placed in another system. Commission: E-commerce often uses the function of commission. For example, the accounting part may be the Committee of the Office. When transactions need to span multiple systems (or multiple databases in a system), decentralized transaction access system materials (or database). If you do not use MS DTC, you cannot ensure that the system transaction is not partially completed. Now let's take a look at how e-commerce transactions use decentralized transactions. This example of the customer is shopping in a credit card. Let's take a look at what steps to complete a transaction.
Explain that there are many kinds of trading methods of e-commerce, and the examples we used here are for teaching reference only, which does not represent the best trading method.
The client has not officially entered the business database through the network. Customers choose product A to put into the electronic shopping cart. To complete the above action, the computer must enter the database to perform two trading steps. a. Search steps, find out that customers are new customers or old customers, if they are old customers to remove their Cust_ID related information. (Some apps are in the purchase steps.) B. Put the product A into the shopping cart. When the customer is preparing to check out, a transaction or a set of trading database begins to perform the following operations: a. Read the shopping cart data sheet to find the merchandise item purchased by the customer. b. Update the order information table, confirm that the new order has been added to the data sheet. c. Update the customer database, confirm that the bill will be sent to the customer. In this example, customer information and order information are in two different databases, so it will be used to decentralized transactions. d. In the shopping cart data sheet, this product is removed from the record. (Some apps will be deleted when the application is processed.) E. When the account data sheet and the order information list is completed, it will begin to recognize the transaction and complete the decentralized transaction. Now, e-merchants will enter the library of warehouse, stockings and prepare for shipments, and complete the details of this procedure are as follows: a. Query and take out the order information list. b. Prepare the goods boxes inquiry. c. The electronic merchant system is connected to the credit card processor for payment requirements. Such trading models are also scattered transactions because the payment requirement is recorded in this unit. (Some applications are paying for payment, this method is not a general normal program because it is required to authorize the credit card center connection as required when settlement, and will be eliminated.) D. Update order information Adopted with the database. The goods successfully reached the customer. In this transaction, if the MS DTC is not used for two-stage transaction recognition, the following issues may be generated: the payment request step is recognized, but the order information sheet is recognized by the database update process, resulting in payment but not shipped. The payment request step is recognized, but the order data sheet is recognized by the database update step, causing the ship to confiscate money. The shipping step is recognized, but it is still not yet. So the most important point of decentralized transactions is to confirm that each database in the transaction must be updated, otherwise it will not be updated. If the transaction process is not coordinated, there is no consistency between the database and cause a lot of errors.
The MS DTC property is previously referred to the importance of the MS DTC in the transaction process. Here we will discuss several ways to start MS DTC. Call is included in the distal program in a decentralized transaction that uses Transact-SQL (T-SQL) instructions to initiate a decentralized transaction in multiple OLE DB data source update information in your application in your application MS DTC instructions. Let you perform a decentralized transaction on your system (Figure 25-7). The SQL Server of the Transaction Initial End of the transaction will perform the necessary operations for all call MS DTCs to perform a decentralized transaction. This action does not need to be manually executed, and SQL Server will help you take all details.
Figure 25-7 SQL Server initialized decentralized transactions
If you use the last way to start a decentralized transaction, the user's application interface and the SQL Server interface on the network communicate with the MS DTC and SQL Server. SQL Server users will help coordinate decentralized transactions. Figure 25-8 As a schema of a dispersion transaction.
Figure 25-8 Infining MS DTC instructions in the application to initialize a decentralized transaction
MS DTC programming This book is not written for program designers, so it will not ink too much in how to use and design scattered transactions; however, this section will simply list several methods that can start decentralized transactions, and use simple transactions Test MS DTC. The following actions can start a decentralized transaction: Access the remote data in a transaction: This transaction will be upgraded to a decentralized transaction. In a transaction, any decentralized query will upgrade the transaction into a decentralized transaction. Execute the Begin Distributed Transaction Directive: You can generate a decentralized transaction. Using the Remote_Proc_Tran-Saction option in the SQL Server installation option: Execute remote calls will immediately upgrade the transaction to a decentralized transaction. Call OLE DB or ODBC functions: OLE DB and SQL Server have syntax for launching a decentralized transaction. Dissatis-taking transactions via T-SQL can be tested for MS DTC. You can use the T-SQL's Begin Distribute Transaction instruction to start a decentralized transaction, perform the approved by the commit directive, the program is as follows: Begin Distributed Transaction
Select Employeeid from Northwind.dbo.employees
SELECT EMP_ID from Pubs.dbo.Employee
Go
Commit
Go
Enter the program code of the previous four lines, then enter the last two stroke code. This allows you to review the transaction in the discrete transaction coordinator (in the component service MMC) folder. To view the folder, please expand the component service → Computer → My computer, and finally expand the Distributed Transaction Coordinator in the Component Services. When the transaction is reviewed, the last two lines in the T-SQL program code are again entered. Note that after the transaction is recognized, this transaction cannot be found in an powertrain. Of course, most of the decentralized trading processes are very complex (including updates and insert), and is not as simple as examples. This example provides a simple test mode only without changing any information table. In general, decentralized transactions will use ODBC or DB-LIB API to call start or stop transactions in one program. The programming and other transactions of a decentralized transaction have a point in different places, that is, when the transaction is established, the automatic accreditation option is turned off to avoid the SQL statement automatic approval transaction. When the application ends in the CommT or Rollback one of the instructions, MS DTC starts two-stage transaction recognition.
Related Information For SQL Server Application, you can refer to Ron Soukup and Kalen Delaney, "INSIDE Microsoft SQL Server 7.0" (Microsoft Press, 1999); if you are using the program is Microsoft Visual Basic, you can refer to William Vaughn "Hitchhiker's Guide TO Visual Basic and SQL Server" (Microsoft Press, 1998).
Managing MS DTC MS DTC is the installation option for Windows 2000. If you need to use this service, you can choose when you install it. There are two ways to start MS DTC: using SQL service administrators or using component services in the system service components (this chapter has an introduction). To open the SQL Server service administrator tool, click Start → Program Set → Microsoft SQL Server → Service Administrator, Figure 25-9 is a service administrator tool. Figure 25-9 Using the SQL Server service administrator to turn on MS DTC
Select the MS DTC in the service drop-down menu. Press Start / Continue to start this service item, and then stop the service item. You can select whether to automatically start the service when booting in the verified block of the lower left. Monitoring MS DTC wants to monitor MS DTC and must use component service management main control stations. Start the main control station (such as the previous demonstration), expand component services → Computer → My Computer → Distributed Transaction Coordinator, as shown in Figure 25-10.
Figure 25-10 "Distributed Transaction Coordinator" in Component Services
Two options can be seen in this data clip: an action list and an action statistics. Direction Laid Out-action List (shown in Figure 25-11) For all the list of decentralized transactions, check the properties of a transaction, and enforce the implementation or abandonment of the transaction. The mode of operation is to select the right button in the out-of-action list, and the appropriate option is selected from the fast display function.
Figure 25-11 "Active Law" display MS DTC transaction
Act-dimensional statistical statistics (as shown in Figure 25-12) can view information of decentralized transactions, such as the transaction pen number, maximum usage, etc., provide an overview of the in-place transaction, and help future capacity planning . If you see, the monitoring of decentralized transactions is not difficult.
Figure 25-12 "Transaction Statistics" display MS DTC transaction
This chapter summarizes in this chapter, learning the operation of MS DTC and decentralized transactions, and also has basic concepts of component services and technologies provided by Windows 2000, and also learned component services in management. The following chapters will learn SQL Server.