Commit 732b3b4b authored by dwentzel's avatar dwentzel

Updated case sensitivity examples

parent 8b17a86e
/*
This is the source code for http://www.davewentzel.com/content/service-broker-demystified-case-sensitivity.
This covers why some SSB object are case-sensitive and some are not.
*/
--basic setup
--create a database that is case-insensitive
CREATE DATABASE SBTest collate latin1_general_ci_ai
GO
ALTER DATABASE SBTest SET NEW_BROKER
GO
USE SBTest
GO
--all of this will work because the case is matched perfectly (binary sort/compare)
CREATE MESSAGE TYPE MyMessageType VALIDATION = NONE;
CREATE CONTRACT MyContract (MyMessageType SENT BY ANY);
CREATE QUEUE MyQueue;
CREATE SERVICE MyService ON QUEUE MyQueue (MyContract);
CREATE QUEUE MyDestinationQueue;
CREATE SERVICE MyDestinationService ON QUEUE MyDestinationQueue (MyContract);
--but what happens if the case is not correct? Note: "MyContract" is wrong
BEGIN TRY
CREATE SERVICE MyBadService ON QUEUE MyQueue (mYcONTRACT);
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
END CATCH
--...in this case the Message Type name case is wrong
BEGIN TRY
CREATE MESSAGE TYPE MyMT VALIDATION = NONE;
CREATE CONTRACT MyNewContract (mYmt SENT BY ANY);
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
END CATCH
--but this is OK? The queue name is the wrong case
BEGIN TRY
CREATE SERVICE MyNewService ON QUEUE mYqUEUE;
SELECT * FROM MYQUEUE;
PRINT 'Service created and queried with the wrong case!'
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
END CATCH
--all SSB objects except queue names are case-sensitive. Queues
--are the only SSB objects that are not "exposed". An exposed object
--is any SSB object that can participate in a dialog message.
--Here is an example
DECLARE @h UNIQUEIDENTIFIER
BEGIN DIALOG CONVERSATION @h
FROM SERVICE [MyService]
TO SERVICE 'MyDestinationService'
ON CONTRACT MyContract
WITH ENCRYPTION = OFF;
SEND ON CONVERSATION @h MESSAGE TYPE MyMessageType ('');
--if there are any errors we will see them in the transmission queue
--or the sender's queue...depending on the error
select count(*) txqueue_errors from sys.transmission_queue
select count(*) MyQueue_errors from MyQueue;
--basic cleanup
USE master;
GO
DROP DATABASE SBTest;
GO
......@@ -14,8 +14,6 @@ This folder contains the source code for my [Service Broker Demystified blog ser
`GUIDs.sql` covers interesting aspects of SET NEW_BROKER vs ENABLE_BROKER.
`ServicesAndQueues.sql` demonstrates why we need to have both service and queue objects in Service Broker.
`URIs.sql` dispels the myth that if you use URI naming that your SQL Server will access external resources for validation.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment