sqloptions:applicationName 标头元素

后续版本的 Microsoft SQL Server 将删除该功能。 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。

sqloptions:applicationName 登录选项使客户端可以指定用于登录的应用程序名称,例如:

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

sqloptions:applicationName 登录选项就是 SOAP 标头。它由一个名为 sqloptions:applicationName 的元素组成。该元素具有一个必需的属性 value。此属性是一个字符串。value 属性指定要为登录设置的“应用程序名称”。此名称将显示在 sys.sysprocesses 兼容性视图的 program_name 列中。

一个 SOAP 请求中只能出现一个 sqloptions:applicationName 可选标头实例。此标头不能显示在 SOAP 响应中。多个选项实例将会生成错误。

服务器可能会限制 sqloptions:applicationName 值的可识别值的范围。如果客户端提交的值超出了允许的范围,则服务器将自行截断该值,截断方式不定。

如果正在使用 SOAP 会话,则此选项必须出现在用于启动 SOAP 会话的同一请求中。如果在任何带有 sqloptions:sqlSession 标头但不包含 initiate 属性的请求中显示此选项,则将生成错误。

以下是 sqloptions:applicationName 选项的架构片断:

<xs:element name="applicationName" form="qualified">
    <xs:annotation>
        <xs:documentation>
            Set the application 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 application name to set for the login.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:element>

示例

以下是在 SOAP 请求和响应消息中使用 sqloptions:applicationName 标头的示例。

请求

<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:applicationName SOAP-ENV:mustUnderstand="1" value="HeadTrax" />
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <sql:sqlbatch>
      <sql:BatchCommands>
         SELECT DISTINCT program_name FROM sysprocesses
         WHERE program_name='HeadTrax'
      </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>
                  <program_name>HeadTrax</program_name>
                </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>

请参阅

参考