共用方式為


sqloptions:environmentChangeNotifications 標頭元素

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

sqloptions:environmentChangeNotifications SOAP 標頭可讓用戶端指定希望接收的環境變更通知,例如:

<SOAP-ENV:Header
  xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/"
  xmlns:sqloptions="https://schemas.microsoft.com/sqlserver/2004/SOAP/Options">
<sqloptions:environmentChangeNotifications           SOAP-ENV:mustUnderstand="1"         databaseChange="true" | "false"          languageChange="true" | "false"          transactionBoundary="true" | "false"  />
</SOAP-ENV:Header>

sqloptions:environmentChangeNotifications 選項會以 SOAP 標頭出現。標頭是由一個名為 sqloptions:environmentChangeNotifications 的元素所組成。此元素有四個選擇性屬性 databaseChange、languageChange、partnerChange 和 transactionBoundary;每一個都是布林值。這四個屬性的預設值都是 false。這些選擇性屬性指定用戶端想要接收的通知。

一個要求中只能包含一個 sqloptions:environmentChangeNotifications 選項的例項。此選項無法出現在回應中。該選項若有多個例項會產生錯誤,在 sqloptions:environmentChangeNotifications 節點中若有任何內容也會產生錯誤。

若目前正在使用 SOAP 工作階段,這個選項便必須和 sqloptions:sqlsession initiate 屬性出現在同一個要求中。如果這個選項出現在任何具有 sqloptions:sqlSession 標頭,但並未包含 initiate 屬性的要求中,便會產生錯誤。

下列是 sqloptions:environmentChangeNotifications 選項的結構描述片段:

<xs:element name="environmentChangeNotifications" form="qualified">
    <xs:annotation>
        <xs:documentation>
            Receive environment change notifications.
        </xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:attribute
          name="databaseChange"
          default="false"
          type="xs:boolean"
          form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    Receive notifications of database changes.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute
          name="languageChange"
          default="false"
          type="xs:boolean"
          form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    Receive notifications of language changes.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute
          name="transactionBoundary"
          default="false"
          type="xs:boolean"
          form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    Receive notifications of transaction boundaries.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="partnerChange" default="false" type="xsd:boolean" form="unqualified">
            <xs:annotation>
                <xs:documentation>Receive notifications of partner changes.</xs:documentation> 
            </xs:annotation>
         </xs:attribute>
    </xs:complexType>
</xs:element>

範例

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

要求

POST !HTTPURL! HTTP/1.1
Content-Type: text/xml
Host: !SERVERNAME!
SOAPAction: "https://schemas.microsoft.com/sqlserver/2004/SOAPsqlbatch"
<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:environmentChangeNotifications           SOAP-ENV:mustUnderstand="1"         databaseChange="true"          languageChange="true"          transactionBoundary="true" />
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <sql:sqlbatch>
      <sql:BatchCommands>
         SET LANGUAGE Italian
         SELECT @@LANGUAGE as lang   
         USE  AdventureWorks2008R2
         BEGIN TRANSACTION testTransaction
         SELECT @@LANGUAGE as language
         COMMIT TRANSACTION testTransaction
       </sql:BatchCommands>
     </sql:sqlbatch>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

回應

<Response>
  <Version>HTTP/1.1</Version>
  <Status>200</Status>
  <StatusText>OK</StatusText>
  <Headers>
    <Content-Type>text/xml; charset=utf-8</Content-Type>
    <Date>exists</Date>
    <Server>Microsoft-SQL/9.0 Microsoft-HTTPAPI/1.0</Server>
    <Transfer-Encoding>chunked</Transfer-Encoding>
  </Headers>
  <Body>
    <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:SqlMessage xsi:type="sqlmessage:SqlMessage">
              <sqlmessage:Class>0</sqlmessage:Class>
              <sqlmessage:LineNumber>0</sqlmessage:LineNumber>
              <sqlmessage:Message>Changed language setting to Italiano.</sqlmessage:Message>
              <sqlmessage:Number>5703</sqlmessage:Number>
              <sqlmessage:Source>Microsoft-SQL/9.0</sqlmessage:Source>
              <sqlmessage:State>1</sqlmessage:State>
            </sqlresultstream:SqlMessage>
            <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>
                    <lang>Italiano</lang>
                  </row>
                </SqlRowSet1>
              </diffgr:diffgram>
            </sqlresultstream:SqlRowSet>
            <sqlresultstream:SqlRowCount xsi:type="sqlrowcount:SqlRowCount">
              <sqlrowcount:Count>1</sqlrowcount:Count>
            </sqlresultstream:SqlRowCount>
            <sqlresultstream:SqlMessage xsi:type="sqlmessage:SqlMessage">
              <sqlmessage:Class>0</sqlmessage:Class>
              <sqlmessage:LineNumber>0</sqlmessage:LineNumber>
              <sqlmessage:Message>Changed database context to 'Northwind'.</sqlmessage:Message>
              <sqlmessage:Number>5701</sqlmessage:Number>
              <sqlmessage:Source>Microsoft-SQL/9.0</sqlmessage:Source>
              <sqlmessage:State>1</sqlmessage:State>
            </sqlresultstream:SqlMessage>
            <sqlresultstream:SqlTransaction xsi:type="sqltransaction:SqlTransaction">
              <sqltransaction:Descriptor>asdf</sqltransaction:Descriptor>
              <sqltransaction:Type>Begin</sqltransaction:Type>
            </sqlresultstream:SqlTransaction>
            <sqlresultstream:SqlRowSet xsi:type="sqlsoaptypes:SqlRowSet">
              <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
                <SqlRowSet2 xmlns="urn:schemas-microsoft-com:sql:SqlRowSet2">
                  <row>
                    <language>Italiano</language>
                  </row>
                </SqlRowSet2>
              </diffgr:diffgram>
            </sqlresultstream:SqlRowSet>
            <sqlresultstream:SqlRowCount xsi:type="sqlrowcount:SqlRowCount">
              <sqlrowcount:Count>1</sqlrowcount:Count>
            </sqlresultstream:SqlRowCount>
            <sqlresultstream:SqlTransaction xsi:type="sqltransaction:SqlTransaction">
              <sqltransaction:Descriptor>asdf</sqltransaction:Descriptor>
              <sqltransaction:Type>Commit</sqltransaction:Type>
            </sqlresultstream:SqlTransaction>
          </sql:sqlbatchResult>
        </sql:sqlbatchResponse>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
  </Body>
</Response>

請參閱

參考