|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Service Broker Error : Cannot find the remote servicequite a long script to make a complet internal example of SB... This test is made on ONE PC with 2 instances... At the end, I have the error message in the title (copy at the end of the script). I cannot arrive to find where is the problem... Many thanks in advance to those that will have the courage to read an play my post ! /******************************************************************* SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN *******************************************************************/ /******************************************************************** * complete example code for "service broker" distributed databases * * Frédéric Brouard - MVP SQL Server * * * * Exchanging data between two servers * * * ********************************************************************* ********************************************************************* * WARNING, the names of the servers must be : * * 1) PTACER-FB\SQL2005BINFINAL, with directory C:\cert1\ * * 2) PTACER-FB\SQL2005BINFINAL2, with directory C:\cert2\ * * if not modify scripts * ********************************************************************/ /* * * * * *** * * CONECT TO SERVEUR 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** -- ETAPE n°0.1 : cleaning server 1 *********************************************************************/ USE master; GO -- supression du point de communication par service web IF EXISTS (SELECT * FROM sys.endpoints WHERE name = 'BrokerEndpoint') DROP ENDPOINT BrokerEndpoint; GO -- suppression des certificats IF EXISTS (SELECT * FROM sys.certificates WHERE name = 'SecuriteTransport1') DROP CERTIFICATE SecuriteTransport1; GO IF EXISTS (SELECT * FROM sys.certificates WHERE name = 'SecuriteTransport2') DROP CERTIFICATE SecuriteTransport2; GO -- suppression de la clef de cryptage DROP MASTER KEY; GO -- suppression du compte de connexion distant ... IF EXISTS (SELECT * FROM sys.server_principals WHERE name = 'LoginDistant1') DROP LOGIN LoginDistant1; GO -- ... et de l'utilisateur rattaché IF EXISTS (SELECT * FROM sys.database_principals WHERE name = 'UtilisateurDistant1') DROP USER UtilisateurDistant1; GO -- effacement des fichiers de sauvegarde des certificats EXEC sp_configure 'show advanced options' , 1; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE WITH OVERRIDE; GO EXEC master..xp_cmdshell 'RMDIR /S /Q "C:\cert1"'; GO EXEC master..xp_cmdshell 'MKDIR "C:\cert1"'; GO -- suppression de la base applicative test IF EXISTS (SELECT * FROM sys.databases WHERE name = 'TEST_SB_DISTANT') DROP DATABASE TEST_SB_DISTANT GO -- liaison des serveurs IF EXISTS (SELECT * FROM sys.sysservers WHERE srvname = 'PTACER-FB\SQL2005BINFINAL2') EXEC sp_dropserver 'PTACER-FB\SQL2005BINFINAL2', 'droplogins'; GO EXEC sp_addlinkedserver N'PTACER-FB\SQL2005BINFINAL2', N'SQL Server' /* * * * * *** * * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] *** * * * * * */ /******************************************************************** -- ETAPE n°0.2 : clean server 2 *********************************************************************/ USE master; GO -- supression du point de communication par service web IF EXISTS (SELECT * FROM sys.endpoints WHERE name = 'BrokerEndpoint') DROP ENDPOINT BrokerEndpoint; GO -- suppression des certificats IF EXISTS (SELECT * FROM sys.certificates WHERE name = 'SecuriteTransport1') DROP CERTIFICATE SecuriteTransport1; GO IF EXISTS (SELECT * FROM sys.certificates WHERE name = 'SecuriteTransport2') DROP CERTIFICATE SecuriteTransport2; GO -- suppression de la clef de cryptage DROP MASTER KEY; GO -- suppression du compte de connexion distant ... IF EXISTS (SELECT * FROM sys.server_principals WHERE name = 'LoginDistant2') DROP LOGIN LoginDistant2; GO -- ... et de l'utilisateur rattaché IF EXISTS (SELECT * FROM sys.database_principals WHERE name = 'UtilisateurDistant2') DROP USER UtilisateurDistant2; GO -- effacement des fichiers de sauvegarde des certificats EXEC sp_configure 'show advanced options' , 1; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE WITH OVERRIDE; GO EXEC master..xp_cmdshell 'RMDIR /S /Q "C:\cert2"'; GO EXEC master..xp_cmdshell 'MKDIR "C:\cert2"'; GO -- suppression de la base applicative test IF EXISTS (SELECT * FROM sys.databases WHERE name = 'TEST_SB_DISTANT') DROP DATABASE TEST_SB_DISTANT GO -- liaison des serveurs IF EXISTS (SELECT * FROM sys.sysservers WHERE srvname = 'PTACER-FB\SQL2005BINFINAL') EXEC sp_dropserver 'PTACER-FB\SQL2005BINFINAL', 'droplogins'; GO EXEC sp_addlinkedserver N'PTACER-FB\SQL2005BINFINAL', N'SQL Server' GO /* * * * * *** * * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** * ETAPE n°1.1 : transport level of Service Broker example * ********************************************************************/ -- paramétrage du format de date à la connexion SET DATEFORMAT ymd; GO USE master; GO -- création d'une clef de cryptage pour la base CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'P@ssw0rd!'; GO -- création d'un certificat dont la clef publique sera utilisée -- pour authentifier les connexions distantes CREATE CERTIFICATE SecuriteTransport1 WITH SUBJECT = 'Certificat pour sécuriser le transport', START_DATE = '2005-12-25'; GO -- le certificat est-il bien créé ? SELECT * FROM sys.certificates; GO -- génération d'un fichier de sauvegarde du certificat en vue de son exportation BACKUP CERTIFICATE SecuriteTransport1 TO FILE = 'C:\cert1\Transport-serv1.cer'; GO -- copie du certificat vers le serveur distant EXEC master..xp_cmdshell 'COPY "C:\cert1\Transport-serv1.cer" "C:\cert2\Transport-serv1.cer"'; GO -- création du point d'accès pour les communications distantes CREATE ENDPOINT BrokerEndpoint STATE = STARTED AS TCP (LISTENER_PORT = 4022) FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE SecuriteTransport1, ENCRYPTION = REQUIRED ); GO -- le point d'accès est-il bien créé ? SELECT * FROM sys.endpoints; GO -- création d'un compte d'utilisateur spécifique au traitement des messages CREATE LOGIN LoginDistant1 WITH PASSWORD = '@rhS0!'; GO CREATE USER UtilisateurDistant1 FROM LOGIN LoginDistant1; GO -- priviliège d'utiliser le point d'accès pour ce nouvel utilisateur GRANT CONNECT ON ENDPOINT::BrokerEndpoint TO LoginDistant1; GO /* * * * * *** * * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] *** * * * * * */ /******************************************************************** * ETAPE n°1.2 : transport level of Service Broker example * ********************************************************************/ -- paramétrage du format de date à la connexion SET DATEFORMAT ymd; GO USE master; GO -- création d'une clef de cryptage pour la base CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'w0rdP@ss!'; GO -- création d'un certificat dont la clef publique sera utilisée -- pour authentifier les connexions distantes CREATE CERTIFICATE SecuriteTransport2 WITH SUBJECT = 'Certificat pour sécuriser le transport', START_DATE = '2005-12-25'; GO -- le certificat est-il bien créé ? SELECT * FROM sys.certificates; GO -- génération d'un fichier de sauvegarde du certificat en vue de son exportation BACKUP CERTIFICATE SecuriteTransport2 TO FILE = 'C:\cert2\Transport-serv2.cer'; GO -- copie du certificat vers le serveur distant EXEC master..xp_cmdshell 'COPY "C:\cert2\Transport-serv2.cer" "C:\cert1\Transport-serv2.cer"'; GO -- création du point d'accès pour les communications distantes CREATE ENDPOINT BrokerEndpoint STATE = STARTED AS TCP (LISTENER_PORT = 4022) FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE SecuriteTransport2, ENCRYPTION = REQUIRED ); GO -- le point d'accès est-il bien créé ? SELECT * FROM sys.endpoints; GO -- création d'un compte d'utilisateur spécifique au traitement des messages CREATE LOGIN LoginDistant2 WITH PASSWORD = 'Z0rglub!'; GO CREATE USER UtilisateurDistant2 FROM LOGIN LoginDistant2; GO -- priviliège d'utiliser le point d'accès pour ce nouvel utilisateur GRANT CONNECT ON ENDPOINT::BrokerEndpoint TO LoginDistant2; GO -- création d'un certificat local en utilisant la sauvegarde du certificat du serveur distant CREATE CERTIFICATE SecuriteTransport1 AUTHORIZATION UtilisateurDistant2 FROM FILE = 'C:\cert2\Transport-serv1.cer'; GO /* * * * * *** * * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** * ETAPE n°1.3 : transport level of Service Broker example * ********************************************************************/ USE master; GO -- création d'un certificat local en utilisant la sauvegarde du certificat du serveur distant CREATE CERTIFICATE SecuriteTransport2 AUTHORIZATION UtilisateurDistant1 FROM FILE = 'C:\cert1\Transport-serv2.cer'; GO /* * * * * *** * * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** * ETAPE n°2.1 : communication level of Service Broker example * ********************************************************************/ SET DATEFORMAT ymd; GO USE master; GO -- création d'une base de données de travail CREATE DATABASE TEST_SB_DISTANT; GO USE TEST_SB_DISTANT; GO -- création de la master key CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'XYZ-123'; GO -- création d'un certificat pour sécuriser le dialogue CREATE CERTIFICATE SecuriteDialogue1 WITH SUBJECT = 'Certificat pour le service Web inventaire', START_DATE = '2005-12-25'; -- notez l'option possible "ACTIVE FOR BEGIN_DIALOG = ON" GO -- exportation du certificat vers le serveur distant BACKUP CERTIFICATE SecuriteDialogue1 TO FILE = 'C:\cert1\Dialogue-serv1.cer'; GO EXEC master..xp_cmdshell 'COPY "C:\cert1\Dialogue-serv1.cer" "C:\cert2\Dialogue-serv1.cer"'; GO -- création d'un compte d'utilisateur spécifique au dialogue CREATE USER UtilDiagDistant1 WITHOUT LOGIN; GO /* * * * * *** * * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] *** * * * * * */ /******************************************************************** * ETAPE n°2.2 : communication level of Service Broker example * ********************************************************************/ USE master; GO -- création d'une base de données de travail CREATE DATABASE TEST_SB_DISTANT; GO USE TEST_SB_DISTANT; GO -- création de la master key CREATE MASTER KEY ENCRYPTION BY PASSWORD = '123-XYZ'; GO -- création d'un certificat pour sécuriser le dialogue CREATE CERTIFICATE SecuriteDialogue2 WITH SUBJECT = 'Certificat pour le service Web inventaire', START_DATE = '2005-12-25'; -- notez l'option possible "ACTIVE FOR BEGIN_DIALOG = ON" GO -- exportation du certificat vers le serveur distant BACKUP CERTIFICATE SecuriteDialogue2 TO FILE = 'C:\cert2\Dialogue-serv2.cer'; GO EXEC master..xp_cmdshell 'COPY "C:\cert2\Dialogue-serv2.cer" "C:\cert1\Dialogue-serv2.cer"'; GO -- création d'un compte d'utilisateur spécifique au dialogue CREATE USER UtilDiagDistant2 WITHOUT LOGIN; GO -- création d'un certificat local en utilisant la sauvegarde du certificat du serveur distant CREATE CERTIFICATE SecuriteDialogue1 AUTHORIZATION UtilDiagDistant2 FROM FILE = 'C:\Cert2\Dialogue-serv1.cer'; GO -- est-il bien créé ? SELECT * FROM sys.certificates; GO /* * * * * *** * * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** * ETAPE n°2.3 : communication level of Service Broker example * ********************************************************************/ USE TEST_SB_DISTANT; GO -- création d'un certificat local en utilisant la sauvegarde du certificat du serveur distant CREATE CERTIFICATE SecuriteDialogue2 AUTHORIZATION UtilDiagDistant1 FROM FILE = 'C:\cert1\Dialogue-serv2.cer'; GO -- le certificat est-il bien créé ? SELECT * FROM sys.certificates; GO /* * * * * *** * * SE CONNECTER AU SERVEUR 1 [PTACER-FB\SQL2005BINFINAL1] *** * * * * * */ /******************************************************************** * ETAPE n°3.1 : fonctionnal level * ********************************************************************/ USE TEST_SB_DISTANT; GO /******************************************************************** * La communication va se faire par des échanges de message XML. * * Voici un exemple d'un tel message : * * <DemandInventaire xmlns="http://ReadySA"> * * <ProductID>1234</ProductID> * * <Quantite>6</Quantite> * * </DemandInventaire> * *******************************************************************/ -- Définition du schéma XML IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'SchemaInventaire') DROP XML SCHEMA COLLECTION SchemaInventaire; GO CREATE XML SCHEMA COLLECTION SchemaInventaire AS '<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ReadySA"> <element name="DemandInventaire" type="anyType"/> <element name="ProductID" type="string"/> <element name="Quantite" type="decimal"/> </schema>'; GO -- ajout de deux types de messages : pour l'envoi et la réception CREATE MESSAGE TYPE sendmsg VALIDATION = VALID_XML WITH SCHEMA COLLECTION SchemaInventaire; GO CREATE MESSAGE TYPE recmsg VALIDATION = WELL_FORMED_XML; GO -- création du contrat : qui envoie quoi ? CREATE CONTRACT Contrat ( sendmsg sent by initiator, recmsg sent by target); GO -- création de la file d'attente du serveur 1 CREATE QUEUE Q_1; -- options de syntaxe supplémentaires : -- WITH ACTIVATION ( -- MAX_QUEUE_READERS = <max_readers>) -- ON <filegroup> GO -- création du service CREATE SERVICE Service1 ON QUEUE Q_1 (Contrat); GO -- création de la route vers le serveur 2 CREATE ROUTE RouteVersSrv2 WITH SERVICE_NAME = 'Service2', ADDRESS = 'LOCAL' GO -- si nous étions sur des serveurs différents, préciser l'URL -- et éventuellement le port d'écoute -- exemple ADDRESS = 'TCP://PTACER-FB:4022'; -- la route est-elle bien créée ? SELECT * FROM sys.routes; GO -- liaison du service distant à l'utilisateur local CREATE REMOTE SERVICE BINDING ServiceDistant TO SERVICE 'Service2' WITH USER = UtilDiagDistant1, ANONYMOUS = Off; GO -- assigne à l'utilisateur local le privilège d'envoi de messages GRANT SEND ON SERVICE::Service1 TO UtilDiagDistant1; GO /* * * * * *** * * SE CONNECTER AU SERVEUR 2 [PTACER-FB\SQL2005BINFINAL2] *** * * * * * */ /******************************************************************** * ETAPE n°3.2 : fonctionnal level * ********************************************************************/ USE TEST_SB_DISTANT; GO -- Définition du schéma XML IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'SchemaInventaire') DROP XML SCHEMA COLLECTION SchemaInventaire; GO CREATE XML SCHEMA COLLECTION SchemaInventaire AS '<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ReadySA"> <element name="DemandInventaire" type="anyType"/> <element name="ProductID" type="string"/> <element name="Quantite" type="decimal"/> </schema>'; GO -- ajout de deux types de messages : pour l'envoi et la réception CREATE MESSAGE TYPE sendmsg VALIDATION = VALID_XML WITH SCHEMA COLLECTION SchemaInventaire; GO CREATE MESSAGE TYPE recmsg VALIDATION = WELL_FORMED_XML; GO -- création du contrat : qui envoie quoi ? CREATE CONTRACT Contrat ( sendmsg sent by initiator, recmsg sent by target); GO -- création de la file d'attente du serveur 2 CREATE QUEUE Q_2; GO -- création du service CREATE SERVICE Service2 ON QUEUE Q_2 (Contrat); GO -- création de la route vers le serveur 1 CREATE ROUTE RouteVersSrv1 WITH SERVICE_NAME = 'Service1', ADDRESS = 'LOCAL' GO -- la route est-elle bien créée ? SELECT * FROM sys.routes; GO -- liaison du service distant à l'utilisateur local CREATE REMOTE SERVICE BINDING ServiceDistant TO SERVICE 'Service1' WITH USER = UtilDiagDistant2, ANONYMOUS = Off; -- assigne à l'utilisateur local le privilège d'envoi de messages GRANT SEND ON SERVICE::Service2 TO UtilDiagDistant2; GO /* * * * * *** * * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] *** * * * * * */ /******************************************************************** * ETAPE n°4.1 : using... an example of dialog * ********************************************************************/ USE TEST_SB_DISTANT; GO -- envoi d'un message bien formé pour test. -- création du document XML contenant le message DECLARE @HDL uniqueidentifier; -- handle de conversation DECLARE @MSG xml; -- contenu du message SET @MSG = '<DemandInventaire xmlns="http://ReadySA"> <ProductID>1234</ProductID> <Quantite>6.6</Quantite> </DemandInventaire>'; -- nos instances sont sur le même serveur. Pour savoir à quel Service Broker -- causer, il nous faut l'identifier au niveau de la base DECLARE @SBID uniqueidentifier; SELECT @SBID = service_broker_guid FROM sys.databases WHERE name = 'TEST_SB_DISTANT' -- démarrage du dialogue BEGIN DIALOG CONVERSATION @HDL FROM SERVICE Service1 TO SERVICE 'Service2', @SBID ON CONTRACT Contrat; -- envoi du message SEND ON CONVERSATION @HDL MESSAGE TYPE sendmsg (@MSG); -- @HDL contient le handle de conversation (GUID) qui va servir de -- "bâton pilote" pour dialoguer entre serveurs --on affiche le message d'erreur SELECT * FROM sys.transmission_queue; SELECT * FROM Q_1 SELECT CAST(message_body as XML) AS MSG FROM Q_1 DECLARE @m xml; --le message DECLARE @h uniqueidentifier; -- le handle sur la conversation RECEIVE @m = message_body,@h = conversation_handle FROM Q_1 SELECT @m; /************************************************************************** SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT END **************************************************************************/ One or more messages could not be delivered to the local service targeted by this dialog. <Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"> <Code>-8490</Code> <Description>Cannot find the remote service 'Service2' because it does not exist.</Description> </Error> Fred Brouard, alias SQLpro http://sqlpro.developpez.com The error in question can happen in only one case: when a BEGIN DIALOG has
the optional @service_broker_id parameter passsed in, but the database with that service_broker_guid does not contain a service as the one requested in the BEGIN DIALOG. From looking to your script, it seems that there are instruction of swithing between the two SQL instances, [PTACER-FB\SQL2005BINFINAL] and [PTACER-FB\SQL2005BINFINAL2]. So, according to the instructions on the script, the 'Service2' will exist only in the TEST_SB_DISTANT database in the [PTACER-FB\SQL2005BINFINAL2] instance. But you are using the @SBID retrieved from the [PTACER-FB\SQL2005BINFINAL] instance, so 'Service2' will be searched in the TEST_SB_DISTANT database on [PTACER-FB\SQL2005BINFINAL], where it won't be found. So you get the error message back. Also, you are using 'LOCAL' routes, even though the dialog is remote. Note that 'LOCAL' means only the current instance, not any instance on the same host. Is not the same as tcp's 'localhost'. You will have to use the address 'tcp://PTACER-FB:...' in the route. Also, be carefull that your endpoints are trying to use the same port number 4022 for both instances, this will not work. One endpoint has to be declared with a different port (e.g. 4023 on [PTACER-FB\SQL2005BINFINAL2]). And of course, the corresponding route on [PTACER-FB\SQL2005BINFINAL] will have to be declared with address 'tcp://PTACER-FB:4023'. See the article on http://blogs.msdn.com/remusrusanu/archive/2005/12/20/506221.aspx for Service Broker troubleshooting steps. Also the article on http://rushi.desai.name/Blog/tabid/54/EntryID/6/Default.aspx shows an alternate way of deploying/configuring services, using a set of stored helper procedures. -- Show quoteThis posting is provided "AS IS" with no warranties, and confers no rights. HTH, ~ Remus Rusanu SQL Service Broker http://msdn2.microsoft.com/en-us/library/ms166043(en-US,SQL.90).aspx "SQLpro" <SQL***@discussions.microsoft.com> wrote in message news:F9BEF248-AB5F-403E-8EF8-59C15ED5B549@microsoft.com... > Hi there, > > quite a long script to make a complet internal example of SB... > > This test is made on ONE PC with 2 instances... > > At the end, I have the error message in the title (copy at the end of the > script). > I cannot arrive to find where is the problem... > > Many thanks in advance to those that will have the courage to read an play > my post ! > > > > > /******************************************************************* > SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN -SCRIPT BEGIN > *******************************************************************/ > > > > /******************************************************************** > * complete example code for "service broker" distributed databases * > * Frédéric Brouard - MVP SQL Server * > * * > * Exchanging data between two servers * > * * > ********************************************************************* > ********************************************************************* > * WARNING, the names of the servers must be : * > * 1) PTACER-FB\SQL2005BINFINAL, with directory C:\cert1\ * > * 2) PTACER-FB\SQL2005BINFINAL2, with directory C:\cert2\ * > * if not modify scripts * > ********************************************************************/ > > > /* > * * > * * > *** * > * CONECT TO SERVEUR 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > > /******************************************************************** > -- ETAPE n°0.1 : cleaning server 1 > *********************************************************************/ > USE master; > GO > > -- supression du point de communication par service web > IF EXISTS (SELECT * > FROM sys.endpoints > WHERE name = 'BrokerEndpoint') > DROP ENDPOINT BrokerEndpoint; > GO > > -- suppression des certificats > IF EXISTS (SELECT * > FROM sys.certificates > WHERE name = 'SecuriteTransport1') > DROP CERTIFICATE SecuriteTransport1; > GO > IF EXISTS (SELECT * > FROM sys.certificates > WHERE name = 'SecuriteTransport2') > DROP CERTIFICATE SecuriteTransport2; > GO > > -- suppression de la clef de cryptage > DROP MASTER KEY; > GO > > -- suppression du compte de connexion distant ... > IF EXISTS (SELECT * > FROM sys.server_principals > WHERE name = 'LoginDistant1') > DROP LOGIN LoginDistant1; > GO > -- ... et de l'utilisateur rattaché > IF EXISTS (SELECT * > FROM sys.database_principals > WHERE name = 'UtilisateurDistant1') > DROP USER UtilisateurDistant1; > GO > > -- effacement des fichiers de sauvegarde des certificats > EXEC sp_configure 'show advanced options' , 1; > EXEC sp_configure 'xp_cmdshell', 1; > RECONFIGURE WITH OVERRIDE; > GO > EXEC master..xp_cmdshell 'RMDIR /S /Q "C:\cert1"'; > GO > EXEC master..xp_cmdshell 'MKDIR "C:\cert1"'; > GO > -- suppression de la base applicative test > IF EXISTS (SELECT * > FROM sys.databases > WHERE name = 'TEST_SB_DISTANT') > DROP DATABASE TEST_SB_DISTANT > GO > -- liaison des serveurs > IF EXISTS (SELECT * > FROM sys.sysservers > WHERE srvname = 'PTACER-FB\SQL2005BINFINAL2') > EXEC sp_dropserver 'PTACER-FB\SQL2005BINFINAL2', 'droplogins'; > GO > EXEC sp_addlinkedserver N'PTACER-FB\SQL2005BINFINAL2', N'SQL Server' > > > /* > * * > * * > *** * > * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] > *** * > * * > * * > */ > > > /******************************************************************** > -- ETAPE n°0.2 : clean server 2 > *********************************************************************/ > USE master; > GO > > -- supression du point de communication par service web > IF EXISTS (SELECT * > FROM sys.endpoints > WHERE name = 'BrokerEndpoint') > DROP ENDPOINT BrokerEndpoint; > GO > > -- suppression des certificats > IF EXISTS (SELECT * > FROM sys.certificates > WHERE name = 'SecuriteTransport1') > DROP CERTIFICATE SecuriteTransport1; > GO > IF EXISTS (SELECT * > FROM sys.certificates > WHERE name = 'SecuriteTransport2') > DROP CERTIFICATE SecuriteTransport2; > GO > > -- suppression de la clef de cryptage > DROP MASTER KEY; > GO > > -- suppression du compte de connexion distant ... > IF EXISTS (SELECT * > FROM sys.server_principals > WHERE name = 'LoginDistant2') > DROP LOGIN LoginDistant2; > GO > -- ... et de l'utilisateur rattaché > IF EXISTS (SELECT * > FROM sys.database_principals > WHERE name = 'UtilisateurDistant2') > DROP USER UtilisateurDistant2; > GO > > -- effacement des fichiers de sauvegarde des certificats > EXEC sp_configure 'show advanced options' , 1; > EXEC sp_configure 'xp_cmdshell', 1; > RECONFIGURE WITH OVERRIDE; > GO > EXEC master..xp_cmdshell 'RMDIR /S /Q "C:\cert2"'; > GO > EXEC master..xp_cmdshell 'MKDIR "C:\cert2"'; > GO > -- suppression de la base applicative test > IF EXISTS (SELECT * > FROM sys.databases > WHERE name = 'TEST_SB_DISTANT') > DROP DATABASE TEST_SB_DISTANT > GO > -- liaison des serveurs > IF EXISTS (SELECT * > FROM sys.sysservers > WHERE srvname = 'PTACER-FB\SQL2005BINFINAL') > EXEC sp_dropserver 'PTACER-FB\SQL2005BINFINAL', 'droplogins'; > GO > EXEC sp_addlinkedserver N'PTACER-FB\SQL2005BINFINAL', N'SQL Server' > GO > > > > /* > * * > * * > *** * > * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°1.1 : transport level of Service Broker example * > ********************************************************************/ > > -- paramétrage du format de date à la connexion > SET DATEFORMAT ymd; > GO > USE master; > GO > > -- création d'une clef de cryptage pour la base > CREATE MASTER KEY > ENCRYPTION BY PASSWORD = 'P@ssw0rd!'; > GO > > -- création d'un certificat dont la clef publique sera utilisée > -- pour authentifier les connexions distantes > CREATE CERTIFICATE SecuriteTransport1 > WITH SUBJECT = 'Certificat pour sécuriser le transport', > START_DATE = '2005-12-25'; > GO > > -- le certificat est-il bien créé ? > SELECT * > FROM sys.certificates; > GO > > -- génération d'un fichier de sauvegarde du certificat en vue de son > exportation > BACKUP CERTIFICATE SecuriteTransport1 > TO FILE = 'C:\cert1\Transport-serv1.cer'; > GO > -- copie du certificat vers le serveur distant > EXEC master..xp_cmdshell 'COPY "C:\cert1\Transport-serv1.cer" > "C:\cert2\Transport-serv1.cer"'; > GO > > -- création du point d'accès pour les communications distantes > CREATE ENDPOINT BrokerEndpoint > STATE = STARTED > AS TCP (LISTENER_PORT = 4022) > FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE SecuriteTransport1, > ENCRYPTION = REQUIRED ); > GO > -- le point d'accès est-il bien créé ? > SELECT * > FROM sys.endpoints; > GO > > -- création d'un compte d'utilisateur spécifique au traitement des > messages > CREATE LOGIN LoginDistant1 > WITH PASSWORD = '@rhS0!'; > GO > CREATE USER UtilisateurDistant1 > FROM LOGIN LoginDistant1; > GO > -- priviliège d'utiliser le point d'accès pour ce nouvel utilisateur > GRANT CONNECT ON ENDPOINT::BrokerEndpoint > TO LoginDistant1; > GO > > > > > > /* > * * > * * > *** * > * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°1.2 : transport level of Service Broker example * > ********************************************************************/ > > -- paramétrage du format de date à la connexion > SET DATEFORMAT ymd; > GO > USE master; > GO > > -- création d'une clef de cryptage pour la base > CREATE MASTER KEY > ENCRYPTION BY PASSWORD = 'w0rdP@ss!'; > GO > > -- création d'un certificat dont la clef publique sera utilisée > -- pour authentifier les connexions distantes > CREATE CERTIFICATE SecuriteTransport2 > WITH SUBJECT = 'Certificat pour sécuriser le transport', > START_DATE = '2005-12-25'; > GO > > -- le certificat est-il bien créé ? > SELECT * > FROM sys.certificates; > GO > > -- génération d'un fichier de sauvegarde du certificat en vue de son > exportation > BACKUP CERTIFICATE SecuriteTransport2 > TO FILE = 'C:\cert2\Transport-serv2.cer'; > GO > -- copie du certificat vers le serveur distant > EXEC master..xp_cmdshell 'COPY "C:\cert2\Transport-serv2.cer" > "C:\cert1\Transport-serv2.cer"'; > GO > > -- création du point d'accès pour les communications distantes > CREATE ENDPOINT BrokerEndpoint > STATE = STARTED > AS TCP (LISTENER_PORT = 4022) > FOR SERVICE_BROKER (AUTHENTICATION = CERTIFICATE SecuriteTransport2, > ENCRYPTION = REQUIRED ); > GO > -- le point d'accès est-il bien créé ? > SELECT * > FROM sys.endpoints; > GO > > -- création d'un compte d'utilisateur spécifique au traitement des > messages > CREATE LOGIN LoginDistant2 > WITH PASSWORD = 'Z0rglub!'; > GO > CREATE USER UtilisateurDistant2 > FROM LOGIN LoginDistant2; > GO > -- priviliège d'utiliser le point d'accès pour ce nouvel utilisateur > GRANT CONNECT ON ENDPOINT::BrokerEndpoint > TO LoginDistant2; > GO > > -- création d'un certificat local en utilisant la sauvegarde du certificat > du serveur distant > CREATE CERTIFICATE SecuriteTransport1 > AUTHORIZATION UtilisateurDistant2 > FROM FILE = 'C:\cert2\Transport-serv1.cer'; > GO > > > > /* > * * > * * > *** * > * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°1.3 : transport level of Service Broker example * > ********************************************************************/ > > USE master; > GO > > -- création d'un certificat local en utilisant la sauvegarde du certificat > du serveur distant > CREATE CERTIFICATE SecuriteTransport2 > AUTHORIZATION UtilisateurDistant1 > FROM FILE = 'C:\cert1\Transport-serv2.cer'; > GO > > > > > /* > * * > * * > *** * > * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > > /******************************************************************** > * ETAPE n°2.1 : communication level of Service Broker example * > ********************************************************************/ > > SET DATEFORMAT ymd; > GO > USE master; > GO > > -- création d'une base de données de travail > CREATE DATABASE TEST_SB_DISTANT; > GO > USE TEST_SB_DISTANT; > GO > > -- création de la master key > CREATE MASTER KEY > ENCRYPTION BY PASSWORD = 'XYZ-123'; > GO > > -- création d'un certificat pour sécuriser le dialogue > CREATE CERTIFICATE SecuriteDialogue1 > WITH SUBJECT = 'Certificat pour le service Web inventaire', > START_DATE = '2005-12-25'; > -- notez l'option possible "ACTIVE FOR BEGIN_DIALOG = ON" > GO > > -- exportation du certificat vers le serveur distant > BACKUP CERTIFICATE SecuriteDialogue1 > TO FILE = 'C:\cert1\Dialogue-serv1.cer'; > GO > EXEC master..xp_cmdshell 'COPY "C:\cert1\Dialogue-serv1.cer" > "C:\cert2\Dialogue-serv1.cer"'; > GO > > -- création d'un compte d'utilisateur spécifique au dialogue > CREATE USER UtilDiagDistant1 > WITHOUT LOGIN; > GO > > /* > * * > * * > *** * > * CONNECT TO SERVER 2 [PTACER-FB\SQL2005BINFINAL2] > *** * > * * > * * > */ > > > /******************************************************************** > * ETAPE n°2.2 : communication level of Service Broker example * > ********************************************************************/ > > > USE master; > GO > > -- création d'une base de données de travail > CREATE DATABASE TEST_SB_DISTANT; > GO > USE TEST_SB_DISTANT; > GO > > -- création de la master key > CREATE MASTER KEY > ENCRYPTION BY PASSWORD = '123-XYZ'; > GO > > -- création d'un certificat pour sécuriser le dialogue > CREATE CERTIFICATE SecuriteDialogue2 > WITH SUBJECT = 'Certificat pour le service Web inventaire', > START_DATE = '2005-12-25'; > -- notez l'option possible "ACTIVE FOR BEGIN_DIALOG = ON" > GO > > -- exportation du certificat vers le serveur distant > BACKUP CERTIFICATE SecuriteDialogue2 > TO FILE = 'C:\cert2\Dialogue-serv2.cer'; > GO > EXEC master..xp_cmdshell 'COPY "C:\cert2\Dialogue-serv2.cer" > "C:\cert1\Dialogue-serv2.cer"'; > GO > > -- création d'un compte d'utilisateur spécifique au dialogue > CREATE USER UtilDiagDistant2 > WITHOUT LOGIN; > GO > > -- création d'un certificat local en utilisant la sauvegarde du certificat > du serveur distant > CREATE CERTIFICATE SecuriteDialogue1 > AUTHORIZATION UtilDiagDistant2 > FROM FILE = 'C:\Cert2\Dialogue-serv1.cer'; > GO > > -- est-il bien créé ? > SELECT * > FROM sys.certificates; > GO > > > /* > * * > * * > *** * > * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°2.3 : communication level of Service Broker example * > ********************************************************************/ > > USE TEST_SB_DISTANT; > GO > > -- création d'un certificat local en utilisant la sauvegarde du certificat > du serveur distant > CREATE CERTIFICATE SecuriteDialogue2 > AUTHORIZATION UtilDiagDistant1 > FROM FILE = 'C:\cert1\Dialogue-serv2.cer'; > GO > > -- le certificat est-il bien créé ? > SELECT * > FROM sys.certificates; > GO > > > > > /* > * * > * * > *** * > * SE CONNECTER AU SERVEUR 1 [PTACER-FB\SQL2005BINFINAL1] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°3.1 : fonctionnal level * > ********************************************************************/ > > > USE TEST_SB_DISTANT; > GO > > /******************************************************************** > * La communication va se faire par des échanges de message XML. * > * Voici un exemple d'un tel message : * > * <DemandInventaire xmlns="http://ReadySA"> * > * <ProductID>1234</ProductID> * > * <Quantite>6</Quantite> * > * </DemandInventaire> * > *******************************************************************/ > > -- Définition du schéma XML > IF EXISTS (SELECT * > FROM sys.xml_schema_collections > WHERE name = 'SchemaInventaire') > DROP XML SCHEMA COLLECTION SchemaInventaire; > GO > CREATE XML SCHEMA COLLECTION SchemaInventaire AS > '<schema xmlns="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://ReadySA"> > <element name="DemandInventaire" type="anyType"/> > <element name="ProductID" type="string"/> > <element name="Quantite" type="decimal"/> > </schema>'; > GO > > -- ajout de deux types de messages : pour l'envoi et la réception > CREATE MESSAGE TYPE sendmsg > VALIDATION = VALID_XML > WITH SCHEMA COLLECTION SchemaInventaire; > GO > CREATE MESSAGE TYPE recmsg > VALIDATION = WELL_FORMED_XML; > GO > > -- création du contrat : qui envoie quoi ? > CREATE CONTRACT Contrat > ( sendmsg sent by initiator, > recmsg sent by target); > GO > > -- création de la file d'attente du serveur 1 > CREATE QUEUE Q_1; > -- options de syntaxe supplémentaires : > -- WITH ACTIVATION ( > -- MAX_QUEUE_READERS = <max_readers>) > -- ON <filegroup> > GO > > -- création du service > CREATE SERVICE Service1 > ON QUEUE Q_1 (Contrat); > GO > > -- création de la route vers le serveur 2 > CREATE ROUTE RouteVersSrv2 > WITH SERVICE_NAME = 'Service2', > ADDRESS = 'LOCAL' > GO > -- si nous étions sur des serveurs différents, préciser l'URL > -- et éventuellement le port d'écoute > -- exemple ADDRESS = 'TCP://PTACER-FB:4022'; > > -- la route est-elle bien créée ? > SELECT * > FROM sys.routes; > GO > > -- liaison du service distant à l'utilisateur local > CREATE REMOTE SERVICE BINDING ServiceDistant > TO SERVICE 'Service2' > WITH USER = UtilDiagDistant1, > ANONYMOUS = Off; > GO > > -- assigne à l'utilisateur local le privilège d'envoi de messages > GRANT SEND ON SERVICE::Service1 > TO UtilDiagDistant1; > GO > > > > /* > * * > * * > *** * > * SE CONNECTER AU SERVEUR 2 [PTACER-FB\SQL2005BINFINAL2] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°3.2 : fonctionnal level * > ********************************************************************/ > > > USE TEST_SB_DISTANT; > GO > > -- Définition du schéma XML > IF EXISTS (SELECT * > FROM sys.xml_schema_collections > WHERE name = 'SchemaInventaire') > DROP XML SCHEMA COLLECTION SchemaInventaire; > GO > CREATE XML SCHEMA COLLECTION SchemaInventaire AS > '<schema xmlns="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://ReadySA"> > <element name="DemandInventaire" type="anyType"/> > <element name="ProductID" type="string"/> > <element name="Quantite" type="decimal"/> > </schema>'; > GO > > -- ajout de deux types de messages : pour l'envoi et la réception > CREATE MESSAGE TYPE sendmsg > VALIDATION = VALID_XML > WITH SCHEMA COLLECTION SchemaInventaire; > GO > CREATE MESSAGE TYPE recmsg > VALIDATION = WELL_FORMED_XML; > GO > > -- création du contrat : qui envoie quoi ? > CREATE CONTRACT Contrat > ( sendmsg sent by initiator, > recmsg sent by target); > GO > > -- création de la file d'attente du serveur 2 > CREATE QUEUE Q_2; > GO > > -- création du service > CREATE SERVICE Service2 > ON QUEUE Q_2 (Contrat); > GO > > -- création de la route vers le serveur 1 > CREATE ROUTE RouteVersSrv1 > WITH SERVICE_NAME = 'Service1', > ADDRESS = 'LOCAL' > GO > > -- la route est-elle bien créée ? > SELECT * > FROM sys.routes; > GO > > -- liaison du service distant à l'utilisateur local > CREATE REMOTE SERVICE BINDING ServiceDistant > TO SERVICE 'Service1' > WITH USER = UtilDiagDistant2, > ANONYMOUS = Off; > > -- assigne à l'utilisateur local le privilège d'envoi de messages > GRANT SEND ON SERVICE::Service2 > TO UtilDiagDistant2; > GO > > > > /* > * * > * * > *** * > * CONNECT TO SERVER 1 [PTACER-FB\SQL2005BINFINAL] > *** * > * * > * * > */ > > /******************************************************************** > * ETAPE n°4.1 : using... an example of dialog * > ********************************************************************/ > > > USE TEST_SB_DISTANT; > GO > > -- envoi d'un message bien formé pour test. > -- création du document XML contenant le message > DECLARE @HDL uniqueidentifier; -- handle de conversation > DECLARE @MSG xml; -- contenu du message > SET @MSG = > '<DemandInventaire xmlns="http://ReadySA"> > <ProductID>1234</ProductID> > <Quantite>6.6</Quantite> > </DemandInventaire>'; > > -- nos instances sont sur le même serveur. Pour savoir à quel Service > Broker > -- causer, il nous faut l'identifier au niveau de la base > DECLARE @SBID uniqueidentifier; > SELECT @SBID = service_broker_guid > FROM sys.databases > WHERE name = 'TEST_SB_DISTANT' > -- démarrage du dialogue > BEGIN DIALOG CONVERSATION @HDL > FROM SERVICE Service1 TO SERVICE 'Service2', @SBID > ON CONTRACT Contrat; > > -- envoi du message > SEND ON CONVERSATION @HDL > MESSAGE TYPE sendmsg (@MSG); > -- @HDL contient le handle de conversation (GUID) qui va servir de > -- "bâton pilote" pour dialoguer entre serveurs > > --on affiche le message d'erreur > SELECT * > FROM sys.transmission_queue; > > SELECT * > FROM Q_1 > > SELECT CAST(message_body as XML) AS MSG > FROM Q_1 > > DECLARE @m xml; --le message > DECLARE @h uniqueidentifier; -- le handle sur la conversation > RECEIVE @m = message_body,@h = conversation_handle > FROM Q_1 > SELECT @m; > > /************************************************************************** > SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT END - SCRIPT > END > **************************************************************************/ > > One or more messages could not be delivered to the local service targeted > by > this dialog. > > <Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"> > <Code>-8490</Code> > <Description>Cannot find the remote service 'Service2' because it does > not > exist.</Description> > </Error> > > Fred Brouard, alias SQLpro > http://sqlpro.developpez.com Thanks.
I will try all this A + Remus Rusanu [MSFT] a écrit: Show quote > The error in question can happen in only one case: when a BEGIN DIALOG has > the optional @service_broker_id parameter passsed in, but the database with > that service_broker_guid does not contain a service as the one requested in > the BEGIN DIALOG. > From looking to your script, it seems that there are instruction of swithing > between the two SQL instances, [PTACER-FB\SQL2005BINFINAL] and > [PTACER-FB\SQL2005BINFINAL2]. > So, according to the instructions on the script, the 'Service2' will exist > only in the TEST_SB_DISTANT database in the [PTACER-FB\SQL2005BINFINAL2] > instance. But you are using the @SBID retrieved from the > [PTACER-FB\SQL2005BINFINAL] instance, so 'Service2' will be searched in the > TEST_SB_DISTANT database on [PTACER-FB\SQL2005BINFINAL], where it won't be > found. So you get the error message back. > > Also, you are using 'LOCAL' routes, even though the dialog is remote. Note > that 'LOCAL' means only the current instance, not any instance on the same > host. Is not the same as tcp's 'localhost'. > You will have to use the address 'tcp://PTACER-FB:...' in the route. Also, > be carefull that your endpoints are trying to use the same port number 4022 > for both instances, this will not work. One endpoint has to be declared with > a different port (e.g. 4023 on [PTACER-FB\SQL2005BINFINAL2]). And of course, > the corresponding route on [PTACER-FB\SQL2005BINFINAL] will have to be > declared with address 'tcp://PTACER-FB:4023'. > > See the article on > http://blogs.msdn.com/remusrusanu/archive/2005/12/20/506221.aspx for Service > Broker troubleshooting steps. > Also the article on > http://rushi.desai.name/Blog/tabid/54/EntryID/6/Default.aspx shows an > alternate way of deploying/configuring services, using a set of stored > helper procedures. > -- Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com Audit, conseil, expertise, formation, modélisation, tuning, optimisation ********************* http://www.datasapiens.com *********************** |
|||||||||||||||||||||||