Compartir a través de


Usar los objetos de error de OLE DB (SQL Server Compact Edition)

Cuando se producen errores durante la ejecución de una aplicación basada en SQL Server 2005 Compact Edition (SQL Server Compact Edition), el proveedor OLE DB para SQL Server Compact Edition devuelve y almacena una matriz de objetos de error. Se puede obtener acceso a estos objetos mediante OLE DB de la forma habitual. El proveedor OLE DB para SQL Server Compact Edition devuelve errores para cada interfaz admitida por el proveedor. Para obtener más información, vea Interfaces OLE DB implementadas (SQL Server Compact Edition). Para obtener información acerca del mecanismo general de recuperación de la información de error por parte de un cliente OLE DB, consulte la sección Microsoft OLE DB de la documentación del SDK de Microsoft Data Access Components (MDAC) en MSDN Library.

Ejemplos

En el siguiente ejemplo se muestra cómo recuperar los números de error específicos del proveedor cuando se utiliza el proveedor OLE DB para SQL Server Compact Edition.

/* 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.
    }
}

Vea también

Referencia

Programar OLE DB para SQL Server Compact Edition

Ayuda e información

Obtener ayuda sobre SQL Server Compact Edition