OLE DB 세션 개체(SQL Server Compact Edition)

세션 개체의 기본 기능은 트랜잭션, 명령 및 행 집합을 정의하고 테이블 및 인덱스를 생성 및 수정하는 것입니다.

세션 개체 사용

Microsoft SQL Server 2005 Compact Edition(SQL Server Compact Edition)에서 세션 속성은 ISessionProperties 인터페이스를 사용하여 설정할 수 있습니다.

세션에서는 다음과 같은 작업을 할 수 있습니다.

  • IDBCreateCommand::CreateCommand를 호출하여 명령 개체를 만듭니다. 단일 세션이 여러 개의 명령을 지원할 수 있습니다. 자세한 내용은 OLE DB 명령(SQL Server Compact Edition)을 참조하십시오.
  • IOpenRowset::OpenRowset를 호출하여 행 집합을 만듭니다. 자세한 내용은 OLE DB 행 집합(SQL Server Compact Edition)을 참조하십시오.
  • IDBSchemaRowset::GetRowset를 호출하여 스키마 행 집합을 만듭니다. SQL Server Compact Edition 에서 지원하는 스키마 행 집합에 대한 자세한 내용은 OLE DB 스키마 행 집합(SQL Server Compact Edition)을 참조하십시오.
  • ITableDefinitionIIndexDefinition을 사용하여 테이블 및 인덱스를 생성 또는 수정합니다.
  • 트랜잭션을 시작하고 종료합니다.

공급자별 세션 속성

SQL Server Compact Edition 에서는 공급자별 속성 DBPROP_SSCE_TRANSACTION_COMMIT_MODE를 지원합니다. 이 속성은 엔진이 커밋 실행 후 버퍼 풀을 플러시할지 여부를 지정하는 데 사용합니다. 이 값을 변경하려면 ISessionProperties 인터페이스에 대한 DBPROPSET_SSCE_SESSION 속성 집합에 DBPROP_SSCE_TRANSACTION_COMMIT_MODE를 전달합니다. 자세한 내용은 공급자별 속성(OLE DB)을 참조하십시오.

다음 예는 세션 개체를 만들고 세션 속성을 수정하여 데이터베이스 엔진이 커밋 실행 후 버퍼 풀을 플러시하도록 하는 방법을 보여 줍니다.

   // Object declarations
HRESULT                  hr=S_OK;
ULONG                    i                    = 0;
DBPROPSET                dbpropset[2];
DBPROP                   dbprop[1];
DBPROP                   sscedbprop[1];

// Declare the provider interfaces.

IDBInitialize *          pIDBInitialize       = NULL;
IDBProperties *          pIDBProperties       = NULL;
IDBCreateSession *       pIDBCreateSession    = NULL;
ISessionProperties *     pISessionProperties  = NULL;
// Initialize the the data source object.
hr = CoCreateInstance(CLSID_SQLSERVERCE_3_0, NULL, CLSCTX_INPROC_SERVER, 
        IID_IDBInitialize, (LPVOID *) &pIDBInitialize);
if (FAILED(hr))
{
    //Send an error-specific message and do error handling.
    goto Exit;
}
// Initialize the the property variants.
for (i = 0; i < sizeof(dbprop)/sizeof(dbprop[0]); i++)
{
    VariantInit(&dbprop[i].vValue);
}
for (i = 0; i < sizeof(sscedbprop)/sizeof(sscedbprop[0]); i++)
{
    VariantInit(&sscedbprop[i].vValue);
}
dbprop[0].dwPropertyID   = DBPROP_INIT_DATASOURCE;
dbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
dbprop[0].vValue.vt = VT_BSTR;
dbprop[0].vValue.bstrVal = SysAllocString(L"\\windows\\Northwind.sdf");
if(NULL == dbprop[0].vValue.bstrVal)
{
    hr = E_OUTOFMEMORY;
    goto Exit; 
}
dbpropset[0].rgProperties    = dbprop;
dbpropset[0].cProperties     = sizeof(dbprop)/sizeof(dbprop[0]);
dbpropset[0].guidPropertySet = DBPROPSET_DBINIT;
// Initialize the property to change the maximum buffer pool size.
sscedbprop[0].dwPropertyID = DBPROP_SSCE_MAXBUFFERSIZE;
sscedbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
sscedbprop[0].vValue.vt = VT_I4;
sscedbprop[0].vValue.lVal = 20*1024; //limit cache usage to 20M, default is 640K
dbpropset[1].rgProperties    = sscedbprop;
dbpropset[1].cProperties     = sizeof(sscedbprop)/sizeof(sscedbprop[0]);
dbpropset[1].guidPropertySet = DBPROPSET_SSCE_DBINIT;
// Set the properties into the provider's data source object.
hr = pIDBInitialize->QueryInterface(IID_IDBProperties,(void**)&pIDBProperties);
if(FAILED(hr))
{
    goto Exit;
}
hr = pIDBProperties->SetProperties(sizeof(dbpropset)/sizeof(dbpropset[0]), 
    dbpropset);
if(FAILED(hr))
{
    goto Exit;
}
// Initialize the data source.
hr = pIDBInitialize->Initialize();
if(FAILED(hr))
{
   goto Exit;
}
// Initialize a session object.
hr = pIDBProperties->QueryInterface(IID_IDBCreateSession, (void **) &pIDBCreateSession);
if (FAILED(hr))
{
    //Send an error-specific message and do error handling.
    goto Exit;
}
hr = pIDBCreateSession->CreateSession(NULL, IID_ISessionProperties, 
    (IUnknown**) &pISessionProperties);
Exit:
    // Clean up resources
    return hr;

참고 항목

도움말 및 정보

SQL Server Compact Edition 지원 정보 보기