473,396 Members | 2,003 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,396 software developers and data experts.

Error Code from SQL Server2000

How can I return an error code from a sql server stored procedure and use it
in my asp page to generate an alert indicating that some error has ocurred?
Jul 22 '05 #1
6 2384
amitavabardhan wrote:
How can I return an error code from a sql server stored procedure and
use it in my asp page to generate an alert indicating that some error
has ocurred?


An error in a procedure should raise a vbscript error. Also, it should show
up in your connection object's Errors collection.

Check out the two articles about error-handling on this site:
http://www.sommarskog.se/index.html

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #2
what I actually meant was that when I am calling a Sql Server stored
procedure from an asp page, then if an error occurs during execution of the
stored procedure, under such circumstances how can I capture that error in
the asp page so as to generate an error message and stop program execution.

"amitavabardhan" wrote:
How can I return an error code from a sql server stored procedure and use it
in my asp page to generate an alert indicating that some error has ocurred?

Jul 22 '05 #3
amitavabardhan wrote:
what I actually meant was that when I am calling a Sql Server stored
procedure from an asp page, then if an error occurs during execution
of the stored procedure, under such circumstances how can I capture
that error in the asp page so as to generate an error message and
stop program execution.


Same answer. Explain why the answer is not sufficient. Do you kinow how to
use On Error Resume Next to trap errors?

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #4
Yes, but how do I return an error message/ code from a sql server stored
procedure to an asp page?

"amitavabardhan" wrote:
How can I return an error code from a sql server stored procedure and use it
in my asp page to generate an alert indicating that some error has ocurred?

Jul 22 '05 #5
Are you replying to me? Please quote some of the message to which you are
replying.
amitavabardhan wrote:
Yes, but how do I return an error message/ code from a sql server
stored procedure to an asp page?


Again, errors are returned automatically to the ADO Connection, which
automatically bubbles them up to the vbscript runtime, which creates an Err
object containing the information, which you can trap using "On Error Resume
Next".
On Error Resume Next
connection.StoredProcedureName parm1,..,parmN
If err <> 0 then
'handle the error
errmsg= err.description
'optionally, check the connection's Errors collection:
if connection.Errors.Count > 0 then
for i = 0 to connection.Errors.Count - 1
errmsg=connection.Errors(i).Description
'etc.
next
end if
end if
The reason for checking the Errors collection is that in some cases,
multiple errors may be returned from the procedure. Only the first error
gets bubbled up to the vbscript runtime. The rest will be found in the
connection's errors collection.

Here is a link to the download location for the vbscript documentation:
http://tinyurl.com/7rk6

You can read the ADO documentation online at:
http://msdn.microsoft.com/library/en...dooverview.asp

Here is some more information about executing stored procedures from ASP:
http://tinyurl.com/jyy0

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #6
Yes Bob, I was replying to you. My sincere apologies for leaving you in
cold....
Thanks for the piece of code on error trapping from stored procedures. I
definitely appreciate you help on this.
"Bob Barrows [MVP]" wrote:
Are you replying to me? Please quote some of the message to which you are
replying.
amitavabardhan wrote:
Yes, but how do I return an error message/ code from a sql server
stored procedure to an asp page?


Again, errors are returned automatically to the ADO Connection, which
automatically bubbles them up to the vbscript runtime, which creates an Err
object containing the information, which you can trap using "On Error Resume
Next".
On Error Resume Next
connection.StoredProcedureName parm1,..,parmN
If err <> 0 then
'handle the error
errmsg= err.description
'optionally, check the connection's Errors collection:
if connection.Errors.Count > 0 then
for i = 0 to connection.Errors.Count - 1
errmsg=connection.Errors(i).Description
'etc.
next
end if
end if
The reason for checking the Errors collection is that in some cases,
multiple errors may be returned from the procedure. Only the first error
gets bubbled up to the vbscript runtime. The rest will be found in the
connection's errors collection.

Here is a link to the download location for the vbscript documentation:
http://tinyurl.com/7rk6

You can read the ADO documentation online at:
http://msdn.microsoft.com/library/en...dooverview.asp

Here is some more information about executing stored procedures from ASP:
http://tinyurl.com/jyy0

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #7

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

Similar topics

1
by: Martin Feuersteiner | last post by:
Dear Group I'm having a very weird problem. Any hints are greatly appreciated. I'm returning two values from a MS SQL Server 2000 stored procedure to my ASP.NET Webapplication and store them...
3
by: laurenq uantrell | last post by:
I am trying to install SQL Server 2000 on a Win2K OS machine but I get this error message: "A previous program installation created pending file operations on the installation machine. You must...
0
by: CAIBird | last post by:
hi, i've been developing a webservice on machine A and one WebMethod of this webservice will connect to SQL Server2000 on machine B using a connect string defined in Web.config as below: <add...
6
by: gabrielvarun | last post by:
Hello everybody, Thanks for everybody who tries to help me out. I need code for connecting to a remote database(Sql server2000) through the vb.net 2003. The sql server will be...
4
by: dgh111 | last post by:
help me one organisation generate one utility in VB programme on NT Server2000 platform and running perfactily. When I change me PC on XP environment and install that utility and running that it...
3
by: dgh111 | last post by:
I Could not understand that where is the problem. Some agency make one small programme for me in NT Server2000 platform and is working properly. But when I change my PC in XP environment that...
1
by: krndhi1983 | last post by:
Hi to All, I am using Windows XP running IIS 6.0.I am developing a project using vb.net 1.1 with SQL Server 2000.It is a mobile project.So i am also using Pocket PC 2002 with SQL CE 2.0.When...
0
by: abhishektech | last post by:
how to call a table from ms access to sql server2000 through coding in sql server2000 query analyzer
1
by: mukeshrasm | last post by:
Hi while restoring database in sql server2000/2005 I am getting this error message: The media set for database nhrc has 2 family members but only 1 are provided. All Members must be...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.