7: Debugging and Error Handling in VS .NET

Maker Data Matrix ECC200 in VS .NET 7: Debugging and Error Handling

7: Debugging and Error Handling
Scanning DataMatrix In .NET Framework
Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in .NET framework applications.
Data Matrix Creator In Visual Studio .NET
Using Barcode drawer for VS .NET Control to generate, create DataMatrix image in Visual Studio .NET applications.
@intStatusId int, @intLeaseId int, @intLeaseScheduleId int, @intOwnerId int, @mnyLease money, @intAcquisitionTypeID int ) As set nocount on SET XACT_ABORT ON begin transaction -- insert asset insert Inventory(EquipmentId, StatusId, LeaseScheduleId, Lease, values ( @intEquipmentId, @intStatusId, @intLeaseScheduleId, @mnyLease,
DataMatrix Reader In Visual Studio .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
Paint Barcode In VS .NET
Using Barcode generation for Visual Studio .NET Control to generate, create barcode image in .NET applications.
LocationId, LeaseId, OwnerId, AcquisitionTypeID) @intLocationId, @intLeaseId, @intOwnerId, @intAcquisitionTypeID)
Barcode Reader In VS .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Data Matrix ECC200 Generation In C#.NET
Using Barcode generation for .NET Control to generate, create DataMatrix image in Visual Studio .NET applications.
-- update total exec prUpdateLeaseSchedule @intLeaseId, @mnyLease commit transaction return (0) GO
DataMatrix Generator In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
Data Matrix ECC200 Creator In VB.NET
Using Barcode creation for .NET framework Control to generate, create Data Matrix image in .NET applications.
Now run them:
2D Barcode Encoder In Visual Studio .NET
Using Barcode maker for VS .NET Control to generate, create Matrix 2D Barcode image in Visual Studio .NET applications.
Creating USS Code 128 In Visual Studio .NET
Using Barcode creator for Visual Studio .NET Control to generate, create Code 128B image in .NET framework applications.
Exec prInsertLeasedAsset_9 @intEquipmentId = 200, @intLocationId = 1, @intStatusId = 1, @intLeaseId = 1, @intLeaseScheduleId = 1, @intOwnerId = 1, @mnyLease = 5000, @intAcquisitionTypeID = 1 -- test transaction select EquipmentId, LocationId, StatusId, Lease from Inventory
Barcode Drawer In .NET Framework
Using Barcode encoder for Visual Studio .NET Control to generate, create barcode image in VS .NET applications.
USPS Confirm Service Barcode Generation In Visual Studio .NET
Using Barcode creation for VS .NET Control to generate, create USPS PLANET Barcode image in Visual Studio .NET applications.
SQL Server 2000 Stored Procedure & XML Programming
Bar Code Maker In VS .NET
Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Code 3/9 Creation In .NET Framework
Using Barcode generation for Reporting Service Control to generate, create Code-39 image in Reporting Service applications.
where EquipmentId = 200 and LocationId = 1
DataMatrix Creator In None
Using Barcode printer for Online Control to generate, create Data Matrix ECC200 image in Online applications.
Recognize USS Code 128 In .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
SQL Server simply stops the execution of the inner stored procedure, but the outer stored procedure continues as though nothing has happened (and even commits the transaction):
DataMatrix Scanner In VB.NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications.
UPC-A Supplement 2 Creator In Visual C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create UPCA image in VS .NET applications.
Server: Msg 208, Level 16, State 1, Procedure prUpdateLeaseSchedule, Line 5 Invalid object name 'LeaseSchedule_NON_EXISTING_TABLE'. EquipmentId LocationId StatusId Lease ----------- ----------- -------- -----------200 1 1 5000.0000
Create Data Matrix In Java
Using Barcode maker for Eclipse BIRT Control to generate, create Data Matrix ECC200 image in Eclipse BIRT applications.
Barcode Recognizer In C#
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
At the time, my expectation was that the Set Xact_Abort statement would abort further execution of everything, as it does in case or runtime errors. Unfortunately, it does not behave in that way. This is potentially very dangerous, but as I said before, problems such as this should be caught during QA phase.
Another Coherent Error Handling Methodology
On a recent .NET project I was involved with, there were many errors when we mixed different types of transactions COM+, DTC, ADO, and T-SQL. Therefore, we decided not to mix them. We went even further and decided not to nest any transactions. If the caller initiates a transaction, the nested procedure skips its own initiation of the transaction. Furthermore, the transaction should be closed only from within the procedure that initiated it. The following procedure records the number of opened transactions on the entry. The Begin Tran statement is preceded by the If statement that initiates the transaction only if the procedure is not already in one transaction:
create procedure dbo.prEquipment_Insert -- insert equipment (and if necessary equipment type) -- (demonstration of alternative method for error handling and transaction processing) @chvMake varchar(50), @chvModel varchar(50), @chvEqType varchar(50), @intEqupmentId int OUTPUT AS
7: Debugging and Error Handling
set xact_abort on set nocount on declare @intTrancountOnEntry int, @intEqTypeId int set @intTrancountOnEntry = @@tranCount -- does such EqType already exist in the database If not exists (Select EqTypeId From EqType Where EqType = @chvEqType) --if it does not exist Begin if @@tranCount = 0 BEGIN TRAN -- insert new EqType in the database Insert EqType (EqType) Values (@chvEqType) -- get id of record that you've just inserted Select @intEqTypeId = @@identity End else begin -- read Id of EqType Select @intEqTypeId From EqType Where EqType = @chvEqType end --insert equipment Insert Equipment (Make, Model, EqTypeId) Values (@chvMake, @chvModel, @intEqTypeId) Select @intEqupmentId = @@identity if @@tranCount > @intTrancountOnEntry COMMIT TRAN return 0
The Commit Tran statement will similarly be executed only if the transaction is initiated in the current procedure.
SQL Server 2000 Stored Procedure & XML Programming
The following procedure demonstrates the way to return logic errors to the caller. Notice that I am using both Raiserror and Return statements. It is very important to use the Return statement to communicate an error to the caller because the caller might not be able to detect the effect of the Raiserror statement.
ALTER Procedure dbo.prInsertInventory_XA -- insert inventory record , update inventory count and return Id -- (demonstration of alternative method for error handling and transaction processing) @intEquipmentId int, @intLocationId int, @inyStatusId tinyint, @intLeaseId int, @intLeaseScheduleId int, @intOwnerId int, @mnsRent smallmoney, @mnsLease smallmoney, @mnsCost smallmoney, @inyAcquisitionTypeID int, @intInventoryId int output As declare @intTrancountOnEntry int set nocount on set xact_abort on set @intTrancountOnEntry = @@tranCount if @@tranCount = 0 begin tran Insert into dbo.Inventory (EquipmentId, LocationId, StatusId, LeaseId, LeaseScheduleId, OwnerId, Rent, Lease, Cost, AcquisitionTypeID) values (@intEquipmentId, @intLocationId, @inyStatusId, @intLeaseId, @intLeaseScheduleId, @intOwnerId, @mnsRent, @mnsLease, @mnsCost, @inyAcquisitionTypeID) select @intInventoryId = Scope_Identity()
Copyright © OnBarcode.com . All rights reserved.