Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

SP warning fails ADO execute

(NOTE: Since this involves both VB and SQL, I am posting this in both forums...)

I have a VB program that uses ADO to execute a stored procedure and get back a recordset as a result. The problem I am having is that a non-fatal warning is being thrown in the stored procedure which seems to generate an error in the VB program.

Within the stored procedure I am creating a temp table and a unique index on one of the fields (using the IGNORE_DUP_KEY flag). During the running of the procedure, there are some records that will try to be inserted that may be duplicates. The procedure throws a message:
"Server: Msg 3604, Level 16, State 1, Procedure sp_IMAGES_QuickSearch, Line 146
Duplicate key was ignored."
and then keeps going. It actually successfully returns the recordset (I have verifed this by running the SP in Query Analyzer).

However, in the VB program, it generates a trappable runtime error. I have this line in the program:
Set rstData = cmdData.Execute()
When it executes (executing the stored procedure), the program jumps down to the error handling code.

So it seems there might be two possible ways to handle this - either prevent the stored procedure from raising the warning, or get the ADO COM object to only fail on errors, not warnings. I do not know how to do either. Any help is appreciated...

Using:
VB6, sp6
MS-SQL 2K

Thanks,
[1433 byte] By [brouse] at [2007-11-11 7:00:00]