473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trapping errors

Hi,
I have a stored proc StoredProc1 =
{
INSERT INTO Table1
SELECT *
FROM View1
Return @@ERROR
}

StoredProc1 is used in another sp StoredProcMain =
{
(some code before)...
EXEC @iResult = StoredProc1
If @iResult <> 0
BEGIN
ROLLBACK TRANSACTION
Return @iResult
END
.... (continue)
}

So I want to rollback if StoredProc1 is not successful.

Then I ran into a problem. I added a column to Table1 but forgot to
update View1 to add the equivalent column. When I executed
StoredProc1, I got the "Insert Error: Column name or number of
supplied values does not match table definition." But the error is
NOT trapped. It seems the instruction "Return @@ERROR" returns 0 and
StoredProcMain goes on as if there wasn't an error.

How can I trap this error?

Thanks
Walter
Jul 20 '05 #1
2 2731

"Walter" <le*****@hotmail.com> wrote in message
news:9a**************************@posting.google.c om...
Hi,
I have a stored proc StoredProc1 =
{
INSERT INTO Table1
SELECT *
FROM View1
Return @@ERROR
}

StoredProc1 is used in another sp StoredProcMain =
{
(some code before)...
EXEC @iResult = StoredProc1
If @iResult <> 0
BEGIN
ROLLBACK TRANSACTION
Return @iResult
END
... (continue)
}

So I want to rollback if StoredProc1 is not successful.

Then I ran into a problem. I added a column to Table1 but forgot to
update View1 to add the equivalent column. When I executed
StoredProc1, I got the "Insert Error: Column name or number of
supplied values does not match table definition." But the error is
NOT trapped. It seems the instruction "Return @@ERROR" returns 0 and
StoredProcMain goes on as if there wasn't an error.

How can I trap this error?

Thanks
Walter


Have a look at this:

http://www.sommarskog.se/error-handl....html#SP-check

This is describing your situation - the INSERT error means that "the
invocation of the procedure as such fails", as Erland puts it, so that the
return code is not set, and @iResult keeps its previous value. That is
presumably 0 in your case, or perhaps NULL if you didn't initialize the
variable. In either case, Erland's solution should work correctly for you.

Simon
Jul 20 '05 #2
"Simon Hayes" <sq*@hayes.ch> wrote in message news:<40**********@news.bluewin.ch>...
"Walter" <le*****@hotmail.com> wrote in message
news:9a**************************@posting.google.c om...
Hi,
I have a stored proc StoredProc1 =
{
INSERT INTO Table1
SELECT *
FROM View1
Return @@ERROR
}

StoredProc1 is used in another sp StoredProcMain =
{
(some code before)...
EXEC @iResult = StoredProc1
If @iResult <> 0
BEGIN
ROLLBACK TRANSACTION
Return @iResult
END
... (continue)
}

So I want to rollback if StoredProc1 is not successful.

Then I ran into a problem. I added a column to Table1 but forgot to
update View1 to add the equivalent column. When I executed
StoredProc1, I got the "Insert Error: Column name or number of
supplied values does not match table definition." But the error is
NOT trapped. It seems the instruction "Return @@ERROR" returns 0 and
StoredProcMain goes on as if there wasn't an error.

How can I trap this error?

Thanks
Walter


Have a look at this:

http://www.sommarskog.se/error-handl....html#SP-check

This is describing your situation - the INSERT error means that "the
invocation of the procedure as such fails", as Erland puts it, so that the
return code is not set, and @iResult keeps its previous value. That is
presumably 0 in your case, or perhaps NULL if you didn't initialize the
variable. In either case, Erland's solution should work correctly for you.

Simon


Many thanks, your information was really good. And the link: right to
the point! Wow!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eitan | last post by:
Hello, I need an example of "Trapping Errors" in ASP (not .net) Thanks :)
3
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
21
by: Neil | last post by:
Is there a way to trap an error generated in another app that is controlled via automation? I have an Access 2000 app that opens Word 2000 and proceeds to open a series of documents and, in each...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
2
by: Fred Nelson | last post by:
I'm devloping a VB.NET web application and I'm having a problem with trapping errors and logging the cause of them. When an unexpected error occurs I want to write it to a file - or e-mail it to...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
1
by: asearle | last post by:
I am a bit new to Perl and am having trouble trapping errors in script ... However, I think that it is just simple syntax issues and hope that someone can point me towards a good HOWTO which might...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.