How is the sql error message number returned in classic asp?

How do I retrieve back the error number 2627 in classic asp?  In stored procedures I can return the error message but not with the below code.  Is there another object or function I could use?

Server: Msg 2627, Level 14, State 1, Line 1

ASP Code
rs.Open sql, con,, adLockOptimistic      
    If err.number <> 0 or con.Errors.Count > 0 Then  
           Response.Write(err.number)  
           Response.Write(err.description)
           Response.Write(con.errors.number)
           Response.Write(con.errors.description)          
    End If
swansonplaceAsked:
Who is Participating?
 
kevp75Connect With a Mentor Commented:
please close the question:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_22973004.html

what you've done is create a 1000 point question which goes against the sites t.o.s.

as to your issue, is this from a stored procedure?  I ask because you could set a return value to equal:
            begin
                  raiserror('Your message',16,1)
                  return -1
            end


have a look here:
http://doc.ddart.net/mssql/sql70/ra-rz_1.htm
0
 
swansonplaceAuthor Commented:
This is called from an asp page.  I know that in stored procedures this specific error can be returned, but using asp as in the code above, the I am not getting the sql duplicate error message.
0
 
swansonplaceAuthor Commented:
Since I have posted the question for 24 hours, and received no responses.  My "ass"umption is that there is not easy way to get the specific sql return code from the inline asp call.  

The post with kevp75 was for stored procedures, and I am not using a stored procedure.  Below is
a snippet of the code, and the way I am retrieving the errors.

ASP Code
rs.Open sql, con,, adLockOptimistic      
    If err.number <> 0 or con.Errors.Count > 0 Then  
           Response.Write(err.number)  
           Response.Write(err.description)
           Response.Write(con.errors.number)
           Response.Write(con.errors.description)          
    End If

Thanks in advance.

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
swansonplaceAuthor Commented:
Since I could not retrieve the sql error messages (am not using stored procedures),  I ended up creating a function that looked for the duplicate inserts, and that allowed me to give my users an error message.

0
 
swansonplaceAuthor Commented:
Thank you.
0
 
swansonplaceAuthor Commented:
Tnank you.
0
All Courses

From novice to tech pro — start learning today.