OLE DB 오류 개체 사용(SQL Server Compact Edition)

SQL Server 2005 Compact Edition(SQL Server Compact Edition) 기반 응용 프로그램을 실행하는 동안 오류가 발생하면 SQL Server Compact Edition 용 OLE DB 공급자는 오류 개체 배열을 반환하고 저장합니다. 그러면 일반적인 방식으로 OLE DB를 사용하여 이들 개체에 액세스할 수 있습니다. SQL Server Compact Edition 용 OLE DB 공급자는 지원되는 각 인터페이스에 대한 오류를 반환합니다. 자세한 내용은 구현된 OLE DB 인터페이스(SQL Server Compact Edition)를 참조하십시오. OLE DB 클라이언트에서 오류 정보를 검색하는 일반적인 메커니즘에 대한 자세한 내용은 MSDN Library에서 MDAC(Microsoft Data Access Components) SDK 설명서의 Microsoft OLE DB 섹션을 참조하십시오.

다음 예에서는 SQL Server Compact Edition 용 OLE DB 공급자를 사용할 때 공급자별 오류 번호를 검색하는 방법을 보여 줍니다.

/* This code sample demonstrates a routine that can handle and display errors from the OLE DB provider for SQL Server Compact Edition. The interface returning the error is pIUnknown, and riid is the REFIID of that interface.*/

// QueryInterface for the ISupportErrorInfo interface
hr = pIUnknown->QueryInterface(IID_ISupportErrorInfo,
    (void**)&pISupportErrorInfo);
if(FAILED(hr) || NULL == pISupportErrorInfo)
    return;

// Determine whether the interface even supports errors. If it does,
// ISupportErrorInfo will return S_OK for that interface.
hr = pISupportErrorInfo->InterfaceSupportsErrorInfo(riid);
pISupportErrorInfo->Release(); // release unnecessary interface

if(S_OK == hr)
{
    // This interface supports returning error information.
    // Get the error object from the system for this thread.
    hr = GetErrorInfo(0, &pIErrorInfo);
    if(FAILED(hr) || NULL == pIErrorInfo)
    {
        return;
    }

    hr = pIErrorInfo->QueryInterface(IID_IErrorRecords,
        (void **) &pIErrorRecords);

    pIErrorInfo->Release();  // Release unnecessary interface

    // Determine the number of records in this error object
    hr = pIErrorRecords->GetRecordCount(&ulNumErrorRecs);

    // Loop over each error record in the error object to display 
    // information about each error. Errors are returned. 
    for (dwErrorIndex = 0; dwErrorIndex < ulNumErrorRecs; dwErrorIndex++) 
    {
        // Attempt to retrieve basic error information for this error.
        hr = pIErrorRecords->GetBasicErrorInfo(dwErrorIndex, &ErrorInfo);

        // Retrieve standard error information for this error.
        hr = pIErrorRecords->GetErrorInfo(dwErrorIndex, NULL,
            &pIErrorInfoRecord);

        // Get the description of the error.
        hr = pIErrorInfoRecord->GetDescription(&bstrDescriptionOfError); 

        // Get the source of the error.
        hr = pIErrorInfoRecord->GetSource(&bstrSourceOfError);

        if(NULL != pIErrorInfoRecord)
        {
            pIErrorInfoRecord->Release(); // Release unnecessary interface
        }

        // Print the native error number for this error. Error numbers are
        // are documented in the Troubleshooting section.
        wprintf(L"Native Error Code: %l\n", ErrorInfo.dwMinor);
    }

    pIErrorRecords->Release();  // Release unnecessary interface.
    }
}

참고 항목

참조

SQL Server Compact Edition용 OLE DB 프로그래밍

도움말 및 정보

SQL Server Compact Edition 지원 정보 보기