Batch Queries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I am executing a batch of insert statements (inserts data to 10 tables)
using SqlCommand - ExecuteNonQuery(). Some of the insert fails even though
the insert query is right.
This happens not all the time but once in a while. so it makes difficult
for me to debug. Any suggestions.

Thanks,
vel.
 
You should proably do some error trapping inside your batch so that you can
debug the issue..

Basic Idea 1 insert, test for error, if an error dosoemthing (rollback
transaction/raise a more specific error/Move to the next insert and return
all errors at the end as a table/.....

Something like
Declare @t table (ernum int, insertnum int)
Declare @er int
insert into X values(x,y,z)
set @er = @@error
if @er <> 0 -- an error happened..
begin
insert into @t values(@er,1)
end

insert into Y values(a,b,c,x,y,z)
set @er = @@error
if @er <> 0 -- an error happened..
begin
insert into @t values(@er,2)
end

insert into Z values(1,2,3,4,55,6,8)
set @er = @@error
if @er <> 0 -- an error happened..
begin
insert into @t values(@er,2)
end
-- Return all errors and which statement failed...
Select * from @t


HTH


Rob
 
Thanks Rob for your suggestions. I will get back after testing with error
tapping code.
 
Back
Top