Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
En SQL Server 2005 Compact Edition (SQL Server Compact Edition), se puede obtener acceso a los errores de los objetos Replication, RemoteDataAccess y Engine directamente en Microsoft Visual C++ for Devices usando los objetos y colecciones de control de errores de SQL Server Compact Edition.
La colección SSCEErrors contiene un objeto SSCEError por cada error generado. Cada objeto SSCEError contiene una colección SSCEParams. La descripción de los errores se puede recuperar en los objetos SSCEParam de la colección SSCEParams. A diferencia de SQL Server, SQL Server Compact Edition devuelve información detallada acerca de un error en forma de colección de seis parámetros. Al crear mensajes de error, use una serie de bucles FOR anidados para recuperar cada objeto SSCEParam de la colección SSCEParams de cada objeto SSCEError.
Los programas nativos hacen referencia a las colecciones y los objetos de error de SQL Server agregando Ca_mergex20.h y Ca_mergex20.lib a las referencias de proyectos y haciendo referencia a estos archivos con la directiva include. Para obtener más información, vea Programar el objeto Native Error (SQL Server Compact Edition).
Ejemplos
El ejemplo siguiente ilustra cómo mostrar los errores de los objetos Replication, RemoteDataAccess y Engine mediante Visual C++ for Devices.
// Error handling example
#include "ca_mergex20.h"
void ShowErrors(ISSCEErrors* pISSCEErrors)
{
HRESULT hr;
LONG cbBuf;
LONG i;
LONG lErrorCount;
LONG lErrorIndex;
LONG lParamCount;
LONG lParamIndex;
VARIANT var;
VARIANT varParam;
WCHAR wszBuff[4096];
WCHAR* pwszBuffPos = &wszBuff[0];
BSTR bstr;
ISSCEError* pISSCEError = NULL;
ISSCEParams* pISSCEParams = NULL;
ISSCEParam* pISSCEParam = NULL;
BOOL fSuccess = FALSE;
// Initialize the variants.
VariantInit(&var);
VariantInit(&varParam);
// Get the count of errors.
if(FAILED(hr = pISSCEErrors->get_Count(&lErrorCount))) goto Exit;
if (lErrorCount <= 0)
{
MessageBox(NULL, L"No extended error information.",L"ShowErrors", MB_OK);
fSuccess = TRUE;
goto Exit;
}
// Display errors, one at a time, in a single message box.
// If there are too many errors, they might not all display correctly.
// If so, we recommend that you perform logic based on the number of errors.
for (lErrorIndex = 0; lErrorIndex < lErrorCount; lErrorIndex++)
{
cbBuf = swprintf(pwszBuffPos, L"E R R O R %d of %d\r\n",
lErrorIndex+1, lErrorCount);
pwszBuffPos += cbBuf;
// Get the next error record.
var.vt = VT_I4;
var.lVal = lErrorIndex;
if(FAILED(hr = pISSCEErrors->get_Item(var, &pISSCEError))) goto Exit;
// Error description
if (FAILED(hr = pISSCEError->get_Description(&bstr))) goto Exit;
cbBuf = swprintf(pwszBuffPos, L"DESCRIPTION: '%s'\r\n", bstr);
pwszBuffPos += cbBuf;
SysFreeString(bstr);
// Error number
if (FAILED(hr = pISSCEError->get_Number(&i))) goto Exit;
cbBuf = swprintf(pwszBuffPos, L"NUMBER: %8.8X\r\n", i);
pwszBuffPos += cbBuf;
// Native error
if (FAILED(hr = pISSCEError->get_NativeError(&i))) goto Exit;
cbBuf = swprintf(pwszBuffPos, L"NATIVE_ERROR: %d\r\n", i);
pwszBuffPos += cbBuf;
// Error source
if (FAILED(hr = pISSCEError->get_Source(&bstr))) goto Exit;
cbBuf = swprintf(pwszBuffPos, L"SOURCE: '%s'\r\n", bstr);
pwszBuffPos += cbBuf;
SysFreeString(bstr);
// Retrieve the error parameters.
if (FAILED(hr = pISSCEError->get_Params(&pISSCEParams))) goto Exit;
// Get the number of error parameters.
if (FAILED(hr = pISSCEParams->get_Count(&lParamCount))) goto Exit;
// Display the value of each parameter.
for (lParamIndex = 0; lParamIndex < lParamCount; lParamIndex++)
{
// Get the parameter object.
var.vt = VT_I4;
var.lVal = lParamIndex;
if (FAILED(hr = pISSCEParams->get_Item(var, &pISSCEParam))) goto Exit;
// Get and display the parameter value.
if (FAILED(hr = pISSCEParam->get_Param(&varParam))) goto Exit;
if (VT_I4 == varParam.vt || VT_UI4 == varParam.vt)
{
cbBuf = swprintf(pwszBuffPos, L"P%d: %d\r\n", lParamIndex,
(LONG) varParam.lVal);
}
else if (VT_I2 == varParam.vt || VT_UI2 == varParam.vt)
{
cbBuf = swprintf(pwszBuffPos, L"P%d: %d\r\n", lParamIndex,
(LONG) varParam.iVal);
}
else if (VT_BSTR == varParam.vt)
{
cbBuf = swprintf(pwszBuffPos, L"P%d: '%s'\r\n", lParamIndex,
varParam.bstrVal);
}
pwszBuffPos += cbBuf;
// Clear the variant.
VariantClear(&varParam);
// Release the parameter object.
pISSCEParam->Release();
pISSCEParam = NULL;
}
cbBuf = swprintf(pwszBuffPos, L"\r\n");
pwszBuffPos += cbBuf;
}
// Display the error information.
MessageBox(NULL, wszBuff,L"Error", MB_OK);
fSuccess = TRUE;
Exit:
// Release the parameter object.
if (pISSCEParam)
{
pISSCEParam->Release();
pISSCEParam = NULL;
}
// Release the parameters object.
if (pISSCEParams)
{
pISSCEParams->Release();
pISSCEParams = NULL;
}
// Release the error object.
if (pISSCEError)
{
pISSCEError->Release();
pISSCEError = NULL;
}
// The Errors object is released in calling routine.
if (!fSuccess)
{
MessageBox(NULL, L"Error while processing errors!",L"ShowErrors", MB_OK);
}
return;
}