sqloptions:initialDatabase 헤더 요소

Microsoft SQL Server의 이후 버전에서는 이 기능이 제거됩니다. 새 개발 작업에서는 이 기능을 사용하지 않도록 하고, 현재 이 기능을 사용하는 응용 프로그램은 수정하십시오.

sqloptions:initialDatabase SOAP 헤더를 사용하여 클라이언트에서는 먼저 연결할 데이터베이스를 다음과 같이 지정할 수 있습니다.

<SOAP-ENV:Header
  xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/"
  xmlns:sqloptions="https://schemas.microsoft.com/sqlserver/2004/SOAP/Options">
    <sqloptions:initialDatabase           SOAP-ENV:mustUnderstand="1"          value="databaseName"           optional="true" | "false"          filename="databaseFileName" />
    
</SOAP-ENV:Header>

sqloptions:initialDatabase 옵션은 SOAP 헤더로 나타나며 sqloptions:initialDatabase라는 하나의 요소로 구성됩니다. 이 요소에는 하나의 필수 특성 value가 있습니다. 이 특성은 문자열 값입니다. value 특성은 처음에 연결할 데이터베이스의 이름을 지정합니다. 문자열은 USE Transact-SQL 명령과 같은 방식으로 해석됩니다. 요소에는 부울 값인 optional(기본값: false)과 문자열 값인 filename(기본값: null)의 두 가지 옵션 특성이 있습니다. optional 특성은 데이터베이스 연결의 실패 여부를 지정합니다. 로그인의 경우 false는 로그인이 실패했음을 의미하고 true는 로그인을 처리할 수 있음을 의미합니다. filename 값은 로그인 시 연결할 데이터베이스의 파일 이름을 제공합니다. 이에 따라 분리된 데이터베이스가 연결되어 사용자가 로그인할 수 있습니다.

sqloptions:initialDatabase 옵션은 한 요청에서 한 번만 나타날 수 있습니다. 이 옵션은 응답에는 나타날 수 없습니다. 이 옵션이 여러 개 나타나면 오류가 발생합니다.

요청을 받은 끝점에 기본 데이터베이스가 구성되면 오류가 발생합니다. 보안을 위해 클라이언트에서는 기본 데이터베이스가 있는 끝점에 sqloptions:initialDatabase 헤더를 지정할 수 없습니다.

SOAP 세션을 사용 중인 경우 이 옵션은 sqloptions:sqlsession initiate 특성과 같은 요청에 나타나야 합니다. sqloptions:sqlSession 헤더가 있으며 initiate 특성이 포함되지 않은 요청에 이 옵션이 나타나면 오류가 발생합니다.

다음은 sqloptions:initialDatabase 옵션에 대한 스키마의 일부분입니다.

<xs:element name="initialDatabase" form="qualified">
    <xs:annotation>
        <xs:documentation>
            Set initial database on login.
        </xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:attribute use="required" name="value" type="xs:string" form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    The name of the initial database to attach to.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute
          name="optional"
          default="false"
          type="xs:boolean"
          form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    Whether the initial database is optional or not.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="filename" type="xs:string" form="unqualified">
            <xs:annotation>
                <xs:documentation>
                    The filename of the database to attach.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:element>

다음은 SOAP 요청 및 응답 메시지 내에 sqloptions:initialDatabase 헤더를 사용하는 예입니다.

요청

<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:initialDatabase SOAP-ENV:mustUnderstand="1" 
                                value="dbTestForAttaching" 
                                optional="false" 
                                filename="!DBDATADIR!\dbTestForAttaching.mdf" />
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <sql:sqlbatch>
      <sql:BatchCommands>
        SELECT name FROM sys.databases WHERE database_id=(SELECT dbid FROM master.dbo.sysprocesses WHERE spid=@@spid)
        SELECT TOP 1 object_id FROM sys.objects WHERE object_id=(SELECT TOP 1 object_id FROM dbTestForAttaching.sys.objects)
      </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>
                <name>dbTestForAttaching</name>
              </row>
            </SqlRowSet1>
          </diffgr:diffgram>
        </sqlresultstream:SqlRowSet>
        <sqlresultstream:SqlRowCount xsi:type="sqlrowcount:SqlRowCount">
          <sqlrowcount:Count>1</sqlrowcount:Count>
        </sqlresultstream:SqlRowCount>
        <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>
                <object_id>val</object_id>
              </row>
            </SqlRowSet2>
          </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>

참고 항목

참조