1. Trang chủ
  2. » Công Nghệ Thông Tin

Microsoft Press Configuring sql server 2005 môn 70 - 431 phần 9 doc

98 192 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

748 Chapter 19 Managing Replication process. If the agent encounters a conflict, it uses a conflict resolver to determine the data that will be propagated to all participants. A conflict resolver is either a Microsoft .NET Framework business component that uses the business logic handler framework included in the namespace Microsoft.SqlServer.Replication.BusinessLogicSupport or a COM-based object that imple- ments the ICustomResolver COM interface. These components are used to resolve merge replication conflicts. SQL Server 2005 provides 12 COM-based resolvers, which Table 19-3 describes. Table 19-3 SQL Server 2005 Conflict Resolvers Name Description Additive Winner determined from the priority value. Specified column set to the sum of the source and the destination column values. Averaging Winner is determined from the priority value. Specified column set to the average of the source and the destination column values. DATETIME (Earlier Wins) Column with the earlier datetime value determines the winner. DATETIME (Later Wins) Column with the later datetime value determines the winner. Maximum Column with the larger numeric value determines the winner. Minimum Column with the smaller numeric value determines the winner. Merge Text Conflict winner is determined from the priority value. The text columns in conflict are set to the merged value, consisting of the common prefix followed by the unique part from the Publisher, then by the delimiter, and finally by the unique part from the Subscriber. Subscriber Always Wins Subscriber, regardless of whether it is the source or destination, is the winner. Priority Column Column with the larger numeric value determines the conflict winner. C1962271X.fm Page 748 Friday, April 29, 2005 8:04 PM Lesson 4: Configuring Conflict Resolution for Merge Replication 749 MORE INFO Microsoft COM-based resolvers For more information about Microsoft COM-based resolvers, see the section “Microsoft COM- Based Resolvers” in SQL Server 2005 Books Online. The previous table is a summary of the more detailed one you can find in Books Online. In some cases, the resolver determines the winner by using a column; in other cases, the winner is determined by the priority, and only the column value will be affected by the resolver. MORE INFO Stored procedure conflict resolvers As an alternative to using a SQL Server 2005 predefined conflict resolver, you can write your own custom conflict resolver as a Transact-SQL stored procedure at each Publisher. During synchroniza- tion, this stored procedure is invoked when conflicts are encountered in an article to which the resolver was registered, and information on the conflict row is passed by the Merge Agent to the required parameters of the procedure. Stored procedure resolvers are invoked only to handle row change–based conflicts. They cannot be used to handle other types of conflicts such as insert fail- ures due to PRIMARY KEY violations or unique index constraint violations. For information about using a stored procedure conflict resolver, see the SQL Server 2005 Books Online article “How to: Implement a Stored Procedure–Based Custom Conflict Resolver for a Merge Article (Replication Transact-SQL Programming).” To configure a resolver, use the New Publication Wizard. In the Articles Definition page, select the table for which you want to configure a resolver. From the Articles Properties drop-down list, select Set Properties Of Highlighted Table Article (see Fig- ure 19-15). Note that you can configure the resolver properties for all tables by select- ing Set Properties Of All Table Articles instead. Upload Only Changes uploaded to the Publisher are accepted; changes are not downloaded to the Subscriber. Download Only Changes uploaded to the Publisher are rejected; changes are downloaded to the Subscriber. Stored Procedure Conflict resolution depends on the logic in the stored procedure you specify. Table 19-3 SQL Server 2005 Conflict Resolvers Name Description C1962271X.fm Page 749 Friday, April 29, 2005 8:04 PM 750 Chapter 19 Managing Replication Figure 19-15 New Publication Wizard: Articles page When you are defining merge replication, the wizard adds a tab to the Article Properties dialog box that you can use to configure the conflict resolver, as shown in Figure 19-16. Figure 19-16 Configuring a conflict resolver C1962271X.fm Page 750 Friday, April 29, 2005 8:04 PM Lesson 4: Configuring Conflict Resolution for Merge Replication 751 You can also use the @article_resolver parameter of the sp_addmergearticle stored pro- cedure to configure a merge replication resolver by using Transact-SQL code. Quick Check ■ You want to configure a custom resolver. Which options do you have? Quick Check Answer ■ You can use one of the following options: ❑ Create a .NET Framework business component. ❑ Create a COM-based object. ❑ Create a custom Transact-SQL stored procedure to use as a conflict resolver. PRACTICE Configuring Merge Replication In this practice, you create and configure a new merge publication. You first delete the previously created secure publication, and then you configure an unsecure merge rep- lication publication with different conflict resolvers. Finally, you test the resolvers and review conflict winners and losers.  Practice 1: Delete the Previous Replication Setup In this practice, you delete the previously defined replication configuration. You won’t disable publishing and distribution, but you will grant SQL Server Agent account access to the snapshot shared folder. 1. Open SSMS. 2. Expand the Replication, Local Publications folder. 3. Right-click the Product publication and choose Delete. 4. Click Yes to confirm the removal of the publication and the subscription. 5. Navigate to the Databases folder. 6. Right-click the SubsTesting database and select Delete. 7. In the Delete Object dialog box, click OK to confirm the removal of the SubsTesting database. 8. Right-click the Databases folder and choose New Database. You will create an empty database that will subscribe to the publication. C1962271X.fm Page 751 Friday, April 29, 2005 8:04 PM 752 Chapter 19 Managing Replication 9. In the Database text box, type SubsTesting as the database name. Click OK to create the database.  Practice 2: Configure a Merge Publication In this practice, you create a merge publication. As part of the configuration process, you assign two different conflict resolvers. 1. If necessary, using SSMS, connect to the server by using Windows authentication. 2. Expand the Replication folder and right-click the Local Publications folder. Choose New Publication, which starts the New Publication Wizard. 3. On the New Publication Wizard page, click Next. 4. On the Publication Database page, select the ReplTesting database and click Next. 5. On the Publication Type page, select Merge Publication. You will create a merge publication to configure conflict resolvers. Click Next. 6. On the Subscriber Types page, verify that the SQL Server 2005 check box is selected and click Next. 7. On the Articles page, expand Tables and select Location, Product, and Product- Inventory. The publication will copy the schema and data of these tables. 8. On the Articles page, select the Show Only Checked Objects In The List check box. This action filters the list and shows only the Location, Product, and Product- Inventory tables. You will configure the Product table to use the standard conflict resolver and the Location and ProductInventory tables to use COM-based resolvers. 9. In the Objects To Publish list, select the Location table, and from the Article Prop- erties drop-down list, select Set Properties Of Highlighted Table Article. 10. Click the Resolver tab and select Use A Custom Resolver (Registered At The Distributor). 11. Select the Microsoft SQL Server DATETIME (Later Wins) Conflict Resolver. 12. In the Enter The Information Needed By The Resolver text box, type Modified- Date. 13. Click OK. The row modified most recently is set as the conflict winner. 14. Select the ProductInventory table, and from the Article Properties drop-down list, select Set Properties Of Highlighted Table Article. C1962271X.fm Page 752 Friday, April 29, 2005 8:04 PM Lesson 4: Configuring Conflict Resolution for Merge Replication 753 15. Click the Resolver tab and select Use A Custom Resolver (Registered At The Distributor). 16. Select the Microsoft SQL Server Minimum Conflict Resolver. 17. In the Enter The Information Needed By The Resolver text box, type Quantity. 18. Click OK. The winning row will always be the Publisher row, but the quantity will always be the minimum of the row. 19. Click Next. 20. Read the Article Issues warning, and click Next. The warning informs users that all merge replication articles must have a uniqueidentifier column, and if they don’t have it, the first snapshot adds a column. Some applications might not handle the schema change appropriately and will stop working as expected. 21. On the Filter Table Rows page, click Next. 22. On the Snapshot Agent page, select both check boxes. You want the Snapshot Agent to run immediately and to create a scheduled job. Click Change to config- ure the schedule. Schedule the Snapshot Agent to run once a week on Sundays at midnight. Click OK to save your changes and then click Next. 23. On the Agent Security page, click Security Settings. 24. Select Run Under The SQL Server Agent Service Account. In the Connect To Publisher section, verify that By Impersonating The Process Account is selected. Click OK and then click Next. CAUTION Setting Snapshot Agent security In this practice, you are configuring the Snapshot Agent to run under the SQL Server Agent security context. In a real-world scenario, this is not a recommended practice; in the previous lesson, you learned how to configure security in a real-world scenario. This practice focuses on merge replication conflict resolvers. 25. On the Wizard Actions page, select both check boxes. You want SSMS to create the publication and the script to have as a reference in the documentation. Click Next. 26. On the Script File Properties page, set the file name to C:\ReplicationPractice\ Scripts\CreateInventoryPublication.sql. Select Overwrite The Existing File and click Next. 27. Name the publication Inventory and review the configuration. Click Finish to create the publication, create the job to run the Snapshot Agent, and create the script. C1962271X.fm Page 753 Friday, April 29, 2005 8:04 PM 754 Chapter 19 Managing Replication 28. After the publication has been created, click Close. 29. Right-click the Inventory Publication and choose Properties. You will configure the Snapshot folder to the local directory instead of the shared folder because the SQL Server Agent service account does not have access to the shared folder. 30. Select the snapshot page. 31. In the Location Of The Snapshot Files section, clear the Put Files In The Default Folder check box and select the Put Files In The Following Folder check box. 32. Set the folder path to: C:\ReplicationPractice\ReplData. Click OK to confirm the new settings.  Practice 3: Subscribe to the Merge Publication In this practice, you create a subscription to the merge publication. 1. If necessary, using SSMS, connect to the server by using Windows authentication. 2. Expand the Replication, Local Publications folder. 3. Right-click the recently created Inventory publication and choose New Subscrip- tions, which will start the New Subscription Wizard. Click Next. 4. On the Publication page, verify that the Inventory publication is selected. Click Next. 5. On the Distribution Agent Location page, verify that Run All Agents At The Dis- tributor (Push Subscriptions) is selected. Click Next to configure push agents to distribute the publication. 6. On the Subscribers page, select the check box for your own server, and from the Subscription Database drop-down list, select the SubsTesting database. This will configure SubsTesting as the Subscriber database. Click Next. 7. On the Distribution Agent Security page, click the (…) button to configure the agent security context. 8. Use the following options: ❑ Run Under The SQL Server Agent Service Account. ❑ In the Connect To The Distributor section, verify that By Impersonating The Process Account is selected. ❑ In the Connect to the Subscriber section, verify that By Impersonating The Process Account is selected. C1962271X.fm Page 754 Friday, April 29, 2005 8:04 PM Lesson 4: Configuring Conflict Resolution for Merge Replication 755 CAUTION Setting the Snapshot Agent security In this practice, you are configuring the Snapshot Agent to run under the SQL Server Agent security context. In a real-world scenario, this is not a recommended practice. 9. Click OK to configure the merge agent’s security and then click Next. 10. On the Synchronization Schedule page, from the Agent Schedule drop-down list, select Define Schedule. Configure the merge agent to run once a week on Sun- days at 00:30, or 12:30 AM. 11. Click OK. This configures the merge agent to run once a week on Sunday at half past midnight. Click Next. 12. On the Initialize Subscriptions page, leave the default option Initialize Immedi- ately. Click Next. 13. Review the default subscription type priority for conflict resolution and click Next. This option sets the subscription priority to 75.00, so changed rows at the subscriber and publisher have the same priority. 14. On the Wizard Actions page, select both check boxes to create the publication and a script to document the configuration. Click Next. 15. On the Script File Properties page, set the file name to C:\ReplicationPractice\ Scripts\CreateProductsSubscription.sql. Select the Overwrite The Existing File option and click Next. 16. Click Finish to create the subscription and the job to run the Distribution Agent. 17. Wait for the subscription to be created, and then click Close.  Practice 4: Verify Merge Conflict Resolution In this practice, you verify that the conflict resolution you configured works as expected. 1. Using SSMS, connect to the server by using Windows authentication. 2. Navigate to the Replication, Local Publications, [ReplTesting]: Inventory publication. 3. Right-click the COMPUTERNAME.SubsTesting subscription and choose View Synchronization Status. 4. Click Start to initiate the Distribution Agent and synchronize the Publisher and the Subscriber. 5. Wait for the agent to replicate and then click Close. C1962271X.fm Page 755 Friday, April 29, 2005 8:04 PM 756 Chapter 19 Managing Replication 6. In the toolbar, click New Query. 7. In the Query Editor, type the following update queries: USE ReplTesting UPDATE Production.Product SET Name=Name+'Updated at Publisher' WHERE ProductID=1 USE SubsTesting UPDATE Production.Product SET Name=Name+'Updated at Subscriber' WHERE ProductID=1 8. Execute the queries and verify that they return the following: (1 row(s) affected) (1 row(s) affected) 9. Navigate to the Replication, Local Publications, [ReplTesting]: Inventory publication. 10. Right-click the COMPUTERNAME.SubsTesting subscription and choose View Synchronization Status. 11. Click Start to initiate the Distribution Agent and synchronize the Publisher and the Subscriber. 12. Wait for the agent to replicate and then click Close. 13. Right-click the [ReplTesting]: Inventory publication and choose View Conflicts. 14. Double-click the Product(1) table. 15. In the Microsoft Replication Conflict Viewer dialog box, review the conflict win- ner and loser. 16. Do not submit the winner or loser. Close the Microsoft Replication Conflict Viewer dialog box. 17. Navigate to the Databases, ReplTesting, Tables, Production.Product table. 18. Right-click the table and choose Open Table. 19. Verify that the Name column for the row with a ProductID of 1 is the one updated at the Publisher. 20. Close the Table window. 21. Navigate to the Databases, SubsTesting, Tables, Production.Product table. 22. Right-click the table and choose Open Table. C1962271X.fm Page 756 Friday, April 29, 2005 8:04 PM Lesson 4: Configuring Conflict Resolution for Merge Replication 757 23. Verify that the Name column for the row with a ProductID of 1 is also the one updated at the Publisher and that both databases have the same value. The merge default conflict resolver chose a winner, and data is consistent in both databases. The conflict winner is always the publisher database. 24. In the toolbar, click New Query. 25. In the Query Editor, type the following queries: USE ReplTesting UPDATE Production.Location SET Name=Name+'Updated at Publisher' WHERE LocationID=1 WAITFOR DELAY '00:00:15' USE SubsTesting UPDATE Production.Location SET Name=Name+'Updated at Subscriber' WHERE LocationID=1 SELECT * FROM ReplTesting.Production.Location WHERE LocationID=1 SELECT * FROM SubsTesting.Production.Location WHERE LocationID=1 26. Execute the queries and verify that the SELECT statements return two rows, and that the ModifiedDate column has a 15-second difference. 27. Navigate to the Replication, Local Publications, [ReplTesting]: Inventory publication. 28. Right-click the COMPUTERNAME.SubsTesting subscription and choose View Synchronization Status. 29. Click Start to initiate the Distribution Agent and synchronize the Publisher and the Subscriber. 30. Wait for the agent to replicate and then click Close. 31. Right-click the [ReplTesting]: Inventory publication and choose View Conflicts. 32. Double-click the Location(1) table. 33. In the Microsoft Replication Conflict Viewer, review the conflict winner and loser. The winner this time is the row updated at the Subscriber because it was the last one you updated. 34. Do not submit the winner or loser. Close the Microsoft Replication Conflict Viewer. C1962271X.fm Page 757 Friday, April 29, 2005 8:04 PM [...]... SSRM by right-clicking the replication folder in SSMS and choosing Launch Replication Monitor Figure 1 9- 1 7 shows the SSRM Alternatively, you can run SSRM from its default path: C:\Program Files \Microsoft SQL Server\ 90 \Tools\Binn\sqlmonitor.exe Figure 1 9- 1 7 SQL Server Replication Monitor C 196 2271X.fm Page 762 Friday, April 29, 2005 8:04 PM 762 Chapter 19 Managing Replication Configuring Non-sysadmin Access... replication? A SQL Server Management Studio (SSMS) B SQL Server Replication Monitor (SSRM) C SQL Server Configuration Manager (SSCM) D SQL Server Error and Usage Reporting (SSEUR) C 196 2271X.fm Page 770 Friday, April 29, 2005 8:04 PM 770 Chapter 19 Managing Replication 2 Which tool should a DBA use to create a baseline to monitor replication? A SQL Server Management Studio (SSMS) B SQL Server Replication... baseline captures a set of measures that you can later compare to measures from the new or modified replication configuration SQL Server 2005 adds 5 performance objects and 12 counters to System Monitor, as Table 1 9- 4 shows Table 1 9- 4 SQL Server 2005 Performance Objects and Counters SQL Server: Replication Counter Description Agents Running The number of replication agents currently running Snapshot Snapshot:... delivered to the Distributor Snapshot: Delivered Trans/sec The number of transactions per second delivered to the Distributor C 196 2271X.fm Page 766 Friday, April 29, 2005 8:04 PM 766 Chapter 19 Managing Replication Table 1 9- 4 SQL Server 2005 Performance Objects and Counters SQL Server: Replication The number of transactions per second delivered to the Distributor The current amount of time, in milliseconds,... the “How to Use the Practice Tests” section in this book’s Introduction C 196 2271X.fm Page 774 Friday, April 29, 2005 8:04 PM C2062271X.fm Page 775 Friday, April 29, 2005 8:06 PM Chapter 20 Working with Service Broker Microsoft SQL Server 2005 introduces Service Broker—a secure, reliable, robust, and highly scalable message-queuing system for distributed applications By providing the core architectural... applications, we recommend The Rational Guide to SQL Server 2005 Service Broker Beta Preview by Roger Wolter (Rational Press, 2005) Although written against the beta version of SQL Server 2005, this book provides a comprehensive review of Service Broker functionality, complete with lots of code samples and practices 775 C2062271X.fm Page 776 Friday, April 29, 2005 8:06 PM 776 Chapter 20 Working with Service... Click OK 7 Close SSMS Practice 2: Monitor Replication with SSRM In this practice, you, as the PublisherUser, use SSRM to review agent history 1 Navigate to Start, All Programs, Microsoft SQL Server 2005 2 Right-click Microsoft SQL Server Management Studio and choose Run As 3 In the Run As window, select The Following User In the User Name text box, type PublisherUser and in the Password text box type P@ssw0rd... error message box C 196 2271X.fm Page 7 69 Friday, April 29, 2005 8:04 PM Lesson 5: Monitoring Replication 7 69 9 Double-click the only subscription in the Subscription grid The Subscription Synchronization History dialog box opens 10 Review the status and article details of the last synchronizations and then close the dialog box 11 In SSRM, select the Warnings And Agents tab 12 Double-click the Snapshot... Estimated lesson time: 30 minutes Using SQL Server Replication Monitor SSRM is the new graphical tool that SQL Server 2005 provides to help you monitor replication agents and the replication process Although you can use SSMS to monitor parts of the replication process or use Transact -SQL or RMO, SSRM is the most important tool for monitoring replication, presenting a Publisher-focused view of all replication... Fault Tolerance for Multiple Servers You are working as the DBA for a large university with seven schools that offer graduate and undergraduate programs The university’s enrollment is growing rapidly, and funds have been approved for seven new servers running SQL Server 2005 one server for each school The servers will support the enrollment application, developed by in-house developers Even when communication . replica- tion configuration. SQL Server 2005 adds 5 performance objects and 12 counters to System Monitor, as Table 1 9- 4 shows. Table 1 9- 4 SQL Server 2005 Performance Objects and Counters SQL Server: . 1 9- 1 7 shows the SSRM. Alternatively, you can run SSRM from its default path: C:Program Files Microsoft SQL Server 90 ToolsBinnsqlmonitor.exe. Figure 1 9- 1 7 SQL Server Replication Monitor C 196 2271X.fm. you specify. Table 1 9- 3 SQL Server 2005 Conflict Resolvers Name Description C 196 2271X.fm Page 7 49 Friday, April 29, 2005 8:04 PM 750 Chapter 19 Managing Replication Figure 1 9- 1 5 New Publication

Ngày đăng: 09/08/2014, 09:21

TỪ KHÓA LIÊN QUAN