AdventureWorks
dbo.uspLogError Stored Procedure
Description
Logs error information in the ErrorLog table about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without inserting error information.
Properties
Creation Date08/01/2010 08:40
Encrypted
Ansi Nulls
Parameters
ParameterDirectionDescriptionData TypeSize
@ErrorLogIDOutOutput parameter for the stored procedure uspLogError. Contains the ErrorLogID value corresponding to the row inserted by uspLogError in the ErrorLog table.int4
@RETURN_VALUEReturn Value int4
Objects that depend on dbo.uspLogError
 Database ObjectObject TypeDescriptionDep Level
dVendor triggerdVendorTriggerINSTEAD OF DELETE trigger which keeps Vendors from being deleted.2
iduSalesOrderDetail triggeriduSalesOrderDetailTriggerAFTER INSERT, DELETE, UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in SalesOrderDetail and updates the SalesOrderHeader.SubTotal column.2
Sales.Individual tableSales.IndividualTableDemographic data about customers that purchase Adventure Works products online.2
iPurchaseOrderDetail triggeriPurchaseOrderDetailTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table and updates the PurchaseOrderHeader.SubTotal column.2
iStore triggeriStoreTriggerAFTER INSERT trigger inserting Store only if the Customer does not exist in the Individual table.2
iuIndividual triggeriuIndividualTriggerAFTER INSERT, UPDATE trigger inserting Individual only if the Customer does not exist in the Store table and setting the ModifiedDate column in the Individual table to the current date.3
iWorkOrder triggeriWorkOrderTriggerAFTER INSERT trigger that inserts a row in the TransactionHistory table.2
Purchasing.ProductVendor tablePurchasing.ProductVendorTableCross-reference table mapping vendors with the products they supply.2
Purchasing.PurchaseOrderDetail tablePurchasing.PurchaseOrderDetailTableIndividual products associated with a specific purchase order. See PurchaseOrderHeader.1
Purchasing.PurchaseOrderHeader tablePurchasing.PurchaseOrderHeaderTableGeneral purchase order information. See PurchaseOrderDetail.1
Sales.SalesOrderDetail tableSales.SalesOrderDetailTableIndividual products associated with a specific sales order. See SalesOrderHeader.1
Sales.SalesOrderHeader tableSales.SalesOrderHeaderTableGeneral sales order information.1
Sales.SalesOrderHeaderSalesReason tableSales.SalesOrderHeaderSalesReasonTableCross-reference table mapping sales orders to sales reason codes.2
Sales.Store tableSales.StoreTableCustomers (resellers) of Adventure Works products.1
Sales.StoreContact tableSales.StoreContactTableCross-reference table mapping stores and their employees.2
dbo.ufnGetContactInformation functiondbo.ufnGetContactInformationUser Defined FunctionTable value function returning the first name, last name, job title and contact type for a given contact.3
uPurchaseOrderDetail triggeruPurchaseOrderDetailTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in PurchaseOrderDetail and updates the PurchaseOrderHeader.SubTotal column.2
uPurchaseOrderHeader triggeruPurchaseOrderHeaderTriggerAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the PurchaseOrderHeader table.2
uSalesOrderHeader triggeruSalesOrderHeaderTriggerAFTER UPDATE trigger that updates the RevisionNumber and ModifiedDate columns in the SalesOrderHeader table.Updates the SalesYTD column in the SalesPerson and SalesTerritory tables.2
HumanResources.uspUpdateEmployeeHireInfo procedureHumanResources.uspUpdateEmployeeHireInfoStored ProcedureUpdates the Employee table and inserts a new row in the EmployeePayHistory table with the values specified in the input parameters.1
HumanResources.uspUpdateEmployeeLogin procedureHumanResources.uspUpdateEmployeeLoginStored ProcedureUpdates the Employee table with the values specified in the input parameters for the given EmployeeID.1
HumanResources.uspUpdateEmployeePersonalInfo procedureHumanResources.uspUpdateEmployeePersonalInfoStored ProcedureUpdates the Employee table with the values specified in the input parameters for the given EmployeeID.1
uWorkOrder triggeruWorkOrderTriggerAFTER UPDATE trigger that inserts a row in the TransactionHistory table, updates ModifiedDate in the WorkOrder table.2
Purchasing.Vendor tablePurchasing.VendorTableCompanies from whom Adventure Works Cycles purchases parts or other goods.1
Purchasing.VendorAddress tablePurchasing.VendorAddressTableCross-reference mapping vendors and addresses.2
Purchasing.VendorContact tablePurchasing.VendorContactTableCross-reference table mapping vendors and their employees.2
Sales.vIndividualCustomer viewSales.vIndividualCustomerViewIndividual customers (names and addresses) that purchase Adventure Works Cycles products online.3
Sales.vIndividualDemographics viewSales.vIndividualDemographicsViewDisplays the content from each element in the xml column Demographics for each customer in the Sales.Individual table.3
Sales.vSalesPersonSalesByFiscalYears viewSales.vSalesPersonSalesByFiscalYearsViewUses PIVOT to return aggregated sales information for each sales representative.2
Sales.vStoreWithDemographics viewSales.vStoreWithDemographicsViewStores (names and addresses) that sell Adventure Works Cycles products to consumers.2
Purchasing.vVendor viewPurchasing.vVendorViewVendor (company) names and addresses and the names of vendor employees to contact.2
Production.WorkOrder tableProduction.WorkOrderTableManufacturing work orders.1
Production.WorkOrderRouting tableProduction.WorkOrderRoutingTableWork order details.2
Objects that dbo.uspLogError depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.ErrorLog tabledbo.ErrorLogTableAudit table tracking errors in the the AdventureWorks database that are caught by the CATCH block of a TRY...CATCH construct. Data is inserted by stored procedure dbo.uspLogError when it is executed from inside the CATCH block of a TRY...CATCH construct.1
dbo.uspPrintError proceduredbo.uspPrintErrorStored ProcedurePrints error information about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without printing any error information.1
Procedure Source Code
CREATE PROCEDURE [dbo].[uspLogError] 
@ErrorLogID [int] = 0 OUTPUT -- contains the ErrorLogID of the row inserted
AS                               
-- by uspLogError in the ErrorLog table
BEGIN
SET NOCOUNT ON;
SET @ErrorLogID = 0;
BEGIN TRY
IF ERROR_NUMBER() IS NULL
RETURN;
IF XACT_STATE() = -1
BEGIN
PRINT 'Cannot log error since the current transaction is in an uncommittable state. ' 
+ 'Rollback the transaction before executing uspLogError in order to successfully log error information.';
RETURN;
END
INSERT [dbo].[ErrorLog] 
(
[UserName], 
[ErrorNumber], 
[ErrorSeverity], 
[ErrorState], 
[ErrorProcedure], 
[ErrorLine], 
[ErrorMessage]
) 
VALUES 
(
CONVERT(sysname, CURRENT_USER), 
ERROR_NUMBER(),
ERROR_SEVERITY(),
ERROR_STATE(),
ERROR_PROCEDURE(),
ERROR_LINE(),
ERROR_MESSAGE()
);
SET @ErrorLogID = @@IDENTITY;
END TRY
BEGIN CATCH
PRINT 'An error occurred in stored procedure uspLogError: ';
EXECUTE [dbo].[uspPrintError];
RETURN -1;
END CATCH
END;
See Also

Related Objects

dbo Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.