How to create a target database

Publisher:Wanderlust123Latest update time:2011-06-16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In this article, you will learn to create the target database and all Service Broker target objects that have no dependencies on the initiator database. Perform these steps from a copy of Management Studio that is running on the same computer as the target instance of the Database Engine.

process
Creating a Service Broker Endpoint
  1. Copy the following code and paste it into the Query Editor window. Then, run the code to create a Service Broker endpoint for this instance of the Database Engine. The Service Broker endpoint establishes the network address to which Service Broker messages are sent. The endpoint uses the Service Broker default TCP port 4022 to establish the remote instance of the Database Engine that will use a Windows Authentication connection to send messages.

    Windows authentication works when both computers are in the same domain or in trusted domains. If the computers are not in trusted domains, use certificate security for the endpoints.

    Copy code
    USE master; GO IF EXISTS (SELECT * FROM master.sys.endpoints WHERE name = N'InstTargetEndpoint') DROP ENDPOINT InstTargetEndpoint; GO CREATE ENDPOINT InstTargetEndpoint STATE = STARTED AS TCP (LISTENER_PORT = 4022) FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS); GO
    
    

Create the target database, master key, and user
  1. Copy the following code and paste it into the query editor window. Change the password in the CREATE MASTER KEY statement. Then, run the code to create the target database for this tutorial. By default, new databases have the ENABLE_BROKER option set to ON. The code also creates a master key and user to support encryption and remote connections.

    USE master; GO IF EXISTS (SELECT * FROM sys.databases WHERE name = N'InstTargetDB') DROP DATABASE InstTargetDB; GO CREATE DATABASE InstTargetDB; GO USE InstTargetDB; GO CREATE MASTER KEY ENCRYPTION BY PASSWORD = N''; GO CREATE USER TargetUser WITHOUT LOGIN; GO
    
    
Create a target certificate
  1. Copy the following code and paste it into the Query Editor window. Change the file name specified in the BACKUP CERTIFICATE statement to reference a folder on your system. Then, run the code to create the target certificate used to encrypt messages. The folder you specify should have permissions set to allow access to the folder only to your Windows account and the Windows account used to run the Database Engine instance, but not to any other account. For Lesson 2, you must manually copy the InstTargetCertificate.cer file to a folder accessible from the initiator instance.

    CREATE CERTIFICATE InstTargetCertificate AUTHORIZATION TargetUser WITH SUBJECT = 'Target Certificate', EXPIRY_DATE = N'12/31/2010'; BACKUP CERTIFICATE InstTargetCertificate TO FILE = N'C:\storedcerts\$ampleSSBCerts\InstTargetCertificate.cer'; GO
    
    
Creating a Message Type
  1. Copy the following code and paste it into the query editor window, then run the code to create a message type for the session. The message type name and properties specified here must be the same as the message type name and properties created in the next lesson in InstInitiatorDB .

    CREATE MESSAGE TYPE [//BothDB/2InstSample/RequestMessage] VALIDATION = WELL_FORMED_XML; CREATE MESSAGE TYPE [//BothDB/2InstSample/ReplyMessage] VALIDATION = WELL_FORMED_XML; GO
    
    
Create a convention
  1. Copy the following code and paste it into the query editor window. Then, run the code to create a convention for the session. The convention name and properties specified here must be the same as the convention name and properties created in the next lesson in InstInitiatorDB .

    CREATE CONTRACT [//BothDB/2InstSample/SimpleContract] ([//BothDB/2InstSample/RequestMessage] SENT BY INITIATOR, [//BothDB/2InstSample/ReplyMessage] SENT BY TARGET ); GO
    
    
Create the target queue and service
  1. Copy the following code and paste it into the query editor window. Then, run the code to create the queue and service to use as the target. The CREATE SERVICE statement associates the service with the InstTargetQueue so that all messages sent to the service are received into the InstTargetQueue . CREATE SERVICE also specifies that only sessions that use the previously created //BothDB/2InstSample/SimpleContract can use the service as a target service.

    Copy code
    CREATE QUEUE InstTargetQueue; CREATE SERVICE [//TgtDB/2InstSample/TargetService] AUTHORIZATION TargetUser ON QUEUE InstTargetQueue ([//BothDB/2InstSample/SimpleContract]); GO
    
    

You have successfully created the database that you will use for this tutorial. Next, you will create InstInitiatorDB and configure it with the objects required to support the Service Broker session initiator endpoint.

Reference address:How to create a target database

Previous article:What is Multisim
Next article:Introduction to Data Collection, Data Collection Terminology

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号