Professional Documents
Culture Documents
1. Click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click
SQL Server Management Studio.
2. In the Connect to Server dialog box, specify the values in the following table, and then click
Connect.
Property Value
Server type Database Engine
Server name MIAMI
Authentication Windows Authentication
1. On the Project menu, click New Query to add a new query file to the project. Connect to
MIAMI by using Windows authentication when prompted.
2. If Solution Explorer is not visible, click Solution Explorer on the View menu.
3. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file to
PrepareDatabase.sql.
4. Add the following Transact-SQL code to the PrepareDatabase.sql query.
USE master
GO
1. On the Project menu, click New Query. Connect to MIAMI by using Windows
authentication when prompted.
2. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file to
CreateServiceBrokerObjects.sql.
3. In the query window, type the following Transact-SQL code to create the message type,
contract, queues, and services.
USE AdventureWorks
GO
-- Create contracts
CREATE CONTRACT [//AW/EMail/SendCustomerDetails]
(
[//AW/EMail/CustomerDetails]
SENT BY INITIATOR
)
GO
-- Create queues
CREATE QUEUE CustomerSvc.NewCustomerQueue
WITH STATUS = ON
-- Create services
CREATE SERVICE [//AW/Sales/CustomerService]
ON QUEUE CustomerSvc.NewCustomerQueue
USE AdventureWorks
GO
1. Examine the following Transact-SQL code in the CreateSendEmailSP.sql query file. Notice
that it contains Transact-SQL statements to create a stored procedure to receive and process
messages in the EmailService service in the AdventureWorks database.
USE AdventureWorks
GO
;RECEIVE TOP(1)
@conversation = conversation_handle,
@msgType = message_type_name,
@msg = message_body
FROM AdventureWorks.EMailSvc.NewCustomerEmailQueue
IF (@@ROWCOUNT = 0) RETURN
IF (@msgType = '//AW/EMail/CustomerDetails')
BEGIN
ELSE IF (@msgType =
'http://schemas.microsoft.com/SQL/ServiceBroker/Error') OR
(@msgType =
'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog')
ELSE
BEGIN
END CONVERSATION @conversation
WITH ERROR = 500 DESCRIPTION = 'Invalid message type.';
1. On the Project menu, click New Query. When prompted, use Windows authentication to
connect to MIAMI.
2. In Solution Explorer, right-click SQLQuery1.sql, and then click Rename. Rename the file
AlterServiceBrokerQueue.sql.
3. In the query window, type the following Transact-SQL statement to make the
EMailSvc.NewCustomerEmailQueue queue activate the
EMailSvc.uspSendCustomerEmail stored procedure.
USE AdventureWorks
GO