Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Error Code from SQL Server2000

Reply
Thread Tools

Error Code from SQL Server2000

 
 
amitavabardhan
Guest
Posts: n/a
 
      05-26-2005
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?
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      05-26-2005
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.


 
Reply With Quote
 
 
 
 
amitavabardhan
Guest
Posts: n/a
 
      05-26-2005
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?

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      05-26-2005
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.


 
Reply With Quote
 
amitavabardhan
Guest
Posts: n/a
 
      05-27-2005
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?

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      05-27-2005
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"


 
Reply With Quote
 
amitavabardhan
Guest
Posts: n/a
 
      05-27-2005
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"
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL ERROR while executing the code java.sql.SQLException: ORA-01008: not all variables bound mahesh Java 3 04-06-2010 10:59 AM
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
Problem connecting to SQL Server2000 using SQLRelay in Python bharat Python 0 11-10-2005 01:11 PM
Server2000, IAS PEAP cannot find certificate andrew.juniper@red-m.com Wireless Networking 1 07-15-2005 08:15 PM
Forms Authentication with SQL Server2000 Andy G ASP .Net Security 1 10-19-2004 06:47 PM



Advertisments