Error Code from SQL Server2000

Discussion in 'ASP General' started by amitavabardhan, May 26, 2005.

  1. 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?
     
    amitavabardhan, May 26, 2005
    #1
    1. Advertising

  2. 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.
     
    Bob Barrows [MVP], May 26, 2005
    #2
    1. Advertising

  3. 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?
     
    amitavabardhan, May 26, 2005
    #3
  4. 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.
     
    Bob Barrows [MVP], May 26, 2005
    #4
  5. 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?
     
    amitavabardhan, May 27, 2005
    #5
  6. 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-us/ado270/htm/dasdkadooverview.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"
     
    Bob Barrows [MVP], May 27, 2005
    #6
  7. 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-us/ado270/htm/dasdkadooverview.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"
    >
    >
    >
     
    amitavabardhan, May 27, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daves
    Replies:
    1
    Views:
    409
  2. bharat
    Replies:
    0
    Views:
    405
    bharat
    Nov 10, 2005
  3. mahesh
    Replies:
    3
    Views:
    4,782
    cb_1987
    Apr 6, 2010
  4. ecoolone
    Replies:
    0
    Views:
    800
    ecoolone
    Jan 3, 2008
  5. Andy G

    Forms Authentication with SQL Server2000

    Andy G, Oct 18, 2004, in forum: ASP .Net Security
    Replies:
    1
    Views:
    141
    Paul Clement
    Oct 19, 2004
Loading...

Share This Page