共用方式為


sqloptions:hostname 標頭元素

未來的 Microsoft SQL Server 版本將移除這項功能。請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。

sqloptions:hostName 登入選項可讓用戶端指定登入的主機名稱,例如:

<SOAP-ENV:Header
  xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/"
  xmlns:sqloptions="https://schemas.microsoft.com/sqlserver/2004/SOAP/Options">
    <sqloptions:hostname           SOAP-ENV:mustUnderstand="1"          value="hostName"/>
    
</SOAP-ENV:Header>

sqloptions:hostName 登入選項會以 SOAP 標頭出現。標頭是由一個名為 sqloptions:hostName 的元素所組成。元素只有一個文字值的強制屬性,即 value。這可讓 host name 設定該登入。這將會出現在 sys.sysprocesses 相容性檢視的 hostname 資料行中。

sqloptions:hostName 選項只能有一個執行個體可以出現在要求中。此選項無法出現在回應中。該選項若有多個執行個體將會產生錯誤。

伺服器有可能限制 sqloptions:hostName 值的可辨識值的範圍。如果用戶端所提交的值是在允許範圍之外,伺服器將會以無訊息模式及未定義的方式截斷值。

如果使用 SOAP 工作階段,此選項必須出現在與 sqloptions:sqlsession initiate 屬性相同的要求中。如果此選項出現在具有 sqloptions:sqlSession 標頭的任何要求中,而且不包含 initiate 屬性,就會產生錯誤。

下列是 sqloptions:hostName 的結構描述片段:

<xs:element name="hostName" form="qualified">
    <xs:annotation>
        <xs:documentation>
            Set the host name for the login.
        </xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:attribute use="required" name="value" type="xs:string" form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    The host name to set for the login.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:element>

範例

下列是使用 sqloptions:hostname 標頭來搭配 SOAP 要求與回應訊息的範例。

要求

<SOAP-ENV:Envelope xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:sql="https://schemas.microsoft.com/sqlserver/2004/SOAP"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:sqlparam="https://schemas.microsoft.com/sqlserver/2004/SOAP/types/SqlParameter"
                   xmlns:sqlsoaptypes="https://schemas.microsoft.com/sqlserver/2004/SOAP/types"
                   xmlns:sqloptions="https://schemas.microsoft.com/sqlserver/2004/SOAP/Options">
  <SOAP-ENV:Header>
    <sqloptions:hostName SOAP-ENV:mustUnderstand="1" value="recep35" />
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <sql:sqlbatch>
      <sql:BatchCommands>
        SELECT hostname FROM sysprocesses 
        WHERE spid=@@spid AND hostName='recep35'
      </sql:BatchCommands>
    </sql:sqlbatch>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

回應

<SOAP-ENV:Envelope xml:space="preserve" 
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/" 
                   xmlns:sql="https://schemas.microsoft.com/sqlserver/2004/SOAP" 
                   xmlns:sqlsoaptypes="https://schemas.microsoft.com/sqlserver/2004/SOAP/types" 
                   xmlns:sqlrowcount="https://schemas.microsoft.com/sqlserver/2004/SOAP/types/SqlRowCount" 
                   xmlns:sqlmessage="https://schemas.microsoft.com/sqlserver/2004/SOAP/types/SqlMessage" 
                   xmlns:sqlresultstream="https://schemas.microsoft.com/sqlserver/2004/SOAP/types/SqlResultStream" 
                   xmlns:sqltransaction="https://schemas.microsoft.com/sqlserver/2004/SOAP/types/SqlTransaction" 
                   xmlns:sqltypes="https://schemas.microsoft.com/sqlserver/2004/sqltypes">
  <SOAP-ENV:Body>
    <sql:sqlbatchResponse>
      <sql:sqlbatchResult>
        <sqlresultstream:SqlRowSet xsi:type="sqlsoaptypes:SqlRowSet">
          <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
            <SqlRowSet1 xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
              <row>
                <hostname>recep35</hostname>
              </row>
            </SqlRowSet1>
          </diffgr:diffgram>
        </sqlresultstream:SqlRowSet>
        <sqlresultstream:SqlRowCount xsi:type="sqlrowcount:SqlRowCount">
          <sqlrowcount:Count>1</sqlrowcount:Count>
        </sqlresultstream:SqlRowCount>
      </sql:sqlbatchResult>
    </sql:sqlbatchResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

請參閱

參考