SQL Server

Published on May 2016 | Categories: Documents | Downloads: 32 | Comments: 0 | Views: 261
of 4
Download PDF   Embed   Report

Comments

Content

SQL SERVER – Intorduction to Service Broker and Sample Script
Service Broker in Microsoft SQL Server 2005 is a new technology that provides messaging and queuing functions between instances. The basic functions of sending and receiving messages forms a part of a “conversation.” Each conversation is considered to be a complete channel of communication. Each Service Broker conversation is considered to be a dialog where two participants are involved. Service broker find applications when single or multiple SQL server instances are used. This functionality helps in sending messages to remote databases on different servers and processing of the messages within a single database. In order to send messages between the instances, the Service Broker uses TCP/IP. This transaction message queuing system enables the developers to build secure and reliable applications, which are scalable. The developers can design applications from independent components known as “services.” If the applications need to avail the functionality of these services, then it sends message to the particular “service.” Loosely coupled applications (programs that exchange messages independently) are supported by the Service broker. The three components of the Service broker are as follows: conversation components (which consist of the conversation groups, conversations and messages); service definition components (which define the conversations); and networking and security components (defines the infrastructure used for exchanging messages between instances) The maintenance of Service Broker is easy and it is a part of the routine database administration procedure. This is because this functionality forms a part of the Database Engine. Service Broker also provides security by preventing unauthorized access from networks and by message encryption. Let us understand Service Broker with simple script. Script contains necessary comments to explain what exactly script is doing.

---------------------------- Service Broker -----------------------In this exercise we will learn how to cofigure Servie Broker and send and recieve messa ges. ------------------------------------------------------------------CREATE DATABASE ServiceBrokerTest GO USE ServiceBrokerTest GO -- Enable Service Broker ALTER DATABASE ServiceBrokerTest SET ENABLE_BROKER GO -- Create Message Type CREATE MESSAGE TYPE SBMessage VALIDATION = NONE GO -- Create Contract CREATE CONTRACT SBContract (SBMessage SENT BY INITIATOR) GO

-- Create Send Queue CREATE QUEUE SBSendQueue GO -- Create Receive Queue CREATE QUEUE SBReceiveQueue GO -- Create Send Service on Send Queue CREATE SERVICE SBSendService ON QUEUE SBSendQueue (SBContract) GO -- Create Receive Service on Recieve Queue CREATE SERVICE SBReceiveService ON QUEUE SBReceiveQueue (SBContract) GO -- Begin Dialog using service on contract DECLARE @SBDialog uniqueidentifier DECLARE @Message NVARCHAR(128) BEGIN DIALOG CONVERSATION @SBDialog FROM SERVICE SBSendService TO SERVICE 'SBReceiveService' ON CONTRACT SBContract WITH ENCRYPTION = OFF -- Send messages on Dialog SET @Message = N'Very First Message'; SEND ON CONVERSATION @SBDialog MESSAGE TYPE SBMessage (@Message) SET @Message = N'Second Message'; SEND ON CONVERSATION @SBDialog MESSAGE TYPE SBMessage (@Message) SET @Message = N'Third Message'; SEND ON CONVERSATION @SBDialog MESSAGE TYPE SBMessage (@Message) GO -- View messages from Receive Queue SELECT CONVERT(NVARCHAR(MAX), message_body) AS Message FROM SBReceiveQueue GO -- Receive messages from Receive Queue RECEIVE TOP(1) CONVERT(NVARCHAR(MAX), message_body) AS Message FROM SBReceiveQueue GO -- Receive messages from Receive Queue RECEIVE CONVERT(NVARCHAR(MAX), message_body) AS Message FROM SBReceiveQueue GO -- Clean Up USE master GO DROP DATABASE ServiceBrokerTest GO

You can download the above script from here. Let me know what do you think of this script and how simply one can configure service broker.

HOW TO: Import/Export SQL Server Maintenance Plan As sqlmaint Utility will be phased out in future versions of SQL Server, Maintenance Planis Microsoft's recommended approach for Database Maintenance tasks by the DBA


Check Database Integrity  Shrink Database  Reorganize Index  Rebuild Index  Update Statistics  Clean Up History  Execute SQL Server Agent Job  Backup Database (Full, Differential, Transaction Log)  Maintenance Cleanup Task Naturally, after spending the time and efforts to setup proper Maintenance Plans, you should save it and re-use elsewhere anytime you can. And here are 2 ways to export the Maintenance Plan in SQL Server 2005 and 2008 The easier GUI way 1. Open SQL Server Management Studio 2. In Object Explorer (left pane), click "Connect", choose "Integration Services..." 3. Login into the SQL Server with credentials 4. Expand SERVERNAME (Integration Services), and you'll see the below structure  Running Packages  Stored Packages  File Systems  MSDB  Maintenance Plans <- this is what you want 5. Right Click on the Maintenance Plan you want to export, and select Export The harder script way

USE MSDB SELECT name ,PlanXML=CAST(CAST(packagedata AS VARBINARY(MAX)) AS XML) FROM sysdtspackages90

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close