SqlMSMQ TEST~



-- Enable CLR Integration
sp_configure 'clr enable', 1
GO
RECONFIGURE
GO

USE wgdb
GO

-- Set TRUSTWORTHY database's option ON
ALTER DATABASE wgdb SET TRUSTWORTHY ON
GO
/* error
--error-------------------------------------------------
The database owner SID recorded in the master database differs from the database
owner SID recorded in database 'FF_Grants_B5_3_1_DB_Migration'.
You should correct this situation by resetting the owner of
database 'FF_Grants_B5_3_1_DB_Migration' using the ALTER AUTHORIZATION statement.
--------------------------------------------------
answer:ALTER AUTHORIZATION ON DATABASE::wgdb TO sa
--------------------------------------------------
*/
-- Add System.Messaging and other assemblies to database
-- remember to check the path to System.Messaging.dll
CREATE ASSEMBLY Messaging
AUTHORIZATION dbo
FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll'
WITH PERMISSION_SET = UNSAFE
GO

-- Add SqlMSMQ assembly
-- remember to set the path to SqlMSMQ.dll correctly
CREATE ASSEMBLY SqlMSMQ
AUTHORIZATION dbo
FROM 'E:\ProjectName\20070826\HLmain\bin\Debug\SqlMSMQ.dll'
WITH PERMISSION_SET = UNSAFE
GO

--drop ASSEMBLY Messaging
--drop ASSEMBLY SqlMSMQ

-- Create procedures
CREATE PROCEDURE uspMSMQSend
@queue  nvarchar(200),
@msg    nvarchar(MAX)
AS EXTERNAL NAME SqlMSMQ.[WJeziorczak.Sql.SqlMSMQ].Send
GO

CREATE PROCEDURE uspMSMQPeek
@queue  nvarchar(200),
@msg    nvarchar(MAX) OUTPUT
AS EXTERNAL NAME SqlMSMQ.[WJeziorczak.Sql.SqlMSMQ].Peek
GO

CREATE PROCEDURE uspMSMQReceive
@queue  nvarchar(200),
@msg    nvarchar(MAX) OUTPUT
AS EXTERNAL NAME SqlMSMQ.[WJeziorczak.Sql.SqlMSMQ].Receive
GO

/*
-- Uncomment this to test SqlMSMQ
EXEC uspMSMQSend '.\private$\hmiservice', '<MESSAGE>Mr. Watson, come here, I need you</MESSAGE>'
GO

DECLARE @text nvarchar(1024)
EXEC uspMSMQPeek '.\private$\hmiservice', @msg = @text OUTPUT
PRINT @text
GO

DECLARE @text nvarchar(1024)
EXEC uspMSMQReceive '.\private$\hmiservice', @msg = @text OUTPUT
PRINT @text
GO

*/
/*
-- Run this after rebuilding assembly
ALTER ASSEMBLY SqlMSMQ
FROM 'D:\Projekty\moje\SqlMSMQ\Bin\Debug\SqlMSMQ.dll'
WITH PERMISSION_SET = UNSAFE
*/


/*
-- Remove procedures and SqlMSMQ from database
DROP PROCEDURE uspMSMQSend
GO
DROP PROCEDURE uspMSMQPeek
GO
DROP PROCEDURE uspMSMQReceive
GO
DROP ASSEMBLY SqlMSMQ
GO
DROP ASSEMBLY Messaging
GO
*/

你可能感兴趣的:(test)