如何:設定匿名對話安全性的目標服務 (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

SQL Server 在與服務進行任何交談時,都會使用對話安全性,期間裝載起始服務的資料庫中,會有一個遠端服務繫結。 如果遠端服務繫結指定 ANONYMOUS = ON,則對話會使用匿名安全性。 在此情況下,目標資料庫不需要包含起始服務的使用者。 起始服務充當目標資料庫中的 public。

若要設定匿名對話安全性的目標服務

  1. 建立不含登入的使用者。

  2. 為使用者建立憑證。

    注意

    必須使用主要金鑰加密憑證。 如需詳細資訊,請參閱 CREATE MASTER KEY (Transact-SQL) (部分機器翻譯)。

  3. 將憑證備份至檔案。

    注意

    僅備份此使用者的憑證。 不要備份或散發與憑證相關聯的私密金鑰。

  4. 授與目標服務使用者從目標服務所使用的佇列接收訊息的權限。

  5. 授與 public 將訊息傳送至目標服務的權限。

  6. 將憑證和目標服務的名稱提供給遠端資料庫的資料庫管理員。

範例

注意

這些範例已經過 SQL Server 2008 R2 (10.50.x) 的驗證。 建議使用 AdventureWorks 範例資料庫中的 AdventureWorks2008R2 範例資料庫來完成這些範例。

最新版的 SQL Server 支援 SQL Server Service Broker。

    USE AdventureWorks2008R2;
    GO

    --------------------------------------------------------------------
    -- This script configures security for a local user in the database.
    -- The script creates a user in this database, creates a certificate
    -- for the user, writes the certificate to the file system, and
    -- grants permissions to the user. Since this service is a target
    -- service, no remote service binding is necessary.

    -- Create a user without a login. For convenience,
    -- the name of the user is based on the name of the
    -- the remote service.

    CREATE USER [SupplierOrdersUser]
        WITHOUT LOGIN;
    GO

    -- Create a certificate for the initiating service
    -- to use to send messages to the target service.

    CREATE CERTIFICATE [SupplierOrdersCertificate]
        AUTHORIZATION [SupplierOrdersUser]
        WITH SUBJECT = 'Certificate for the SupplierOrders service user.';
    GO

    -- Backup the certificate. Provide the certificate file
    -- to the administrator for the database that hosts
    -- the other service.

    BACKUP CERTIFICATE [SupplierOrdersCertificate]
       TO FILE = 'C:\Certificates\SupplierOrders.cer';
    GO

    -- Grant receive on the orders queue to the local user.

    GRANT RECEIVE ON SupplierOrdersQueue
        TO [SupplierOrdersUser];
    GO

    -- Grant send on the service to public.

    GRANT SEND ON SERVICE::[SupplierOrders] TO public ;

另請參閱