 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 13th, 2009, 03:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Retrieve error desription for SQL Stored Procedure
is it possible to retrieve an error message from sql server stored prodedure and read it in my asp code?
for example, if i try to enter a dup key, can i pass the following stock SQL error message to asp from sql:
Server: Msg 547, Level 16, State 1, Procedure procReenrollmentContractHistoryAddUpdate, Line 50
INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_reenrollmentContractHistory_reenrollmentContra ctTypeMaster'. The conflict occurred in database 'cmProd', table 'reenrollmentContractTypeMaster', column 'contractType'.
The statement has been terminated.
If i am executing one insert statement in my stored procedure and there's a problem, my asp WILL get this error message. However, i'm having a problem when I execute a select statement (which runs fine) and then execute an update statement which fails with a dup key. For some reason, my asp does not get the dup key message (probably b/c the select statement completed successfully).
See below. this is the code i'm having trouble with: (note that when i run it as is and force a dup key error, my asp shows no error. however when i comment out the exec procUpdateGetVariousNumbers2 statement, I DO receive a sql error in asp),
BEGIN TRANSACTION
set @logStatus = 'ADD'
exec procUpdateGetVariousNumbers2 'reenrollmentContractHistoryID', @logUser, @reenrollmentContractHistoryRecID output
insert reenrollmentContractHistory
select
@reenrollmentContractHistoryRecID,
@contractType,
@academicYear,
null, --paymentOption,
null, --tuitionRefundPlanYN,
null, --lunchPlanOption,
null, --tuitionAmount,
null, --tuitionDepositAmount,
null, --faAwardAmount,
null, --faScholarshipName,
null, --faScholarshipAmount,
null, --faDepositAmount,
null, --lunchAmount,
@contractText,
null, --@cshAdminUpdateName,
null, --@cshAdminUpdateDateTime,
null, --@cshAdminUpdateExplanation,
null, --@cshAdminApprovaleSignature,
null, --@cshAdminApprovaleSignatureDateTime,
parentID,
PrimaryAddressee,
PrimarySalutation,
NamePrefix,
FirstName,
MiddleName,
LastName,
NameSuffix,
reenrollmentStudentGrade,
reenrollmentStudentReenrollmentStatus,
reenrollmentStudentType,
constituentStatus,
@logUser,
@logDateTime,
@logStatus
Last edited by srotondo; November 13th, 2009 at 03:30 PM..
|
|

November 13th, 2009, 04:32 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
ADO Limitation?
Could my problem be due to a limitiation in ADO--it can only handle errors for one statement at a time?
If so, can i create the error description in the stored procedure and pass it to my ADO?
I know how to pass out the @@error number, but how do i get the description and pass it out in an output parm?
thank you!
|
|

November 13th, 2009, 04:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It's been a while, but I think you can use the Errors collection on the Connection: http://msdn.microsoft.com/en-us/libr...SQL.80%29.aspx
Cheers,
Imar
|
|

November 13th, 2009, 04:57 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Still a problem with ADO
Imar,
thank you for your quick response.
I'm actually using what's specified in the link you sent me, however, it seems the ADO cannot handle multiple statements--it merely reports back on what happened in the first statement (error or success) and blows off the 2nd statement (see excerpt from Microsoft below--red bold).
what i want to do now is find a way do this: when i encounter an error in sql server stored procedure, save the error message text in a variable and pass it back to ado in an output parm. what do you think?
thank you for your help.
sal
=================
exerpt from Microsoft:
ADO applications use the Errors collection and the Error object to return provider-specific error information to an application. The Errors collection contains the errors generated by a single operation. Each Error object constitutes one such error in the collection. To get information about an error, query the properties of an Error object from the Connection object. To get all the Error objects in the Errors collection, use code to loop through the collection.
|
|

November 13th, 2009, 05:03 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Before you go that route, gave you tried
SET NOCOUNT ON
in your stored procedure? That "mutes" the output from the select statement and maybe allows the error message to bubble up...
Imar
|
|

November 13th, 2009, 05:11 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
yes. i did that but it didn't solve the problem.
thank you.
any thoughts on extracting the error message description from the stored procedure? is it possible?
sal
|
|

November 13th, 2009, 05:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It depends on the version of SQL Server you're using. Take a look under "client-side error handling" of this article:
http://www.sommarskog.se/error-handling-I.html
Imar
|
|

November 13th, 2009, 05:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thank you very much for your time!
have a wonderful weekend.
sal
|
|

November 14th, 2009, 04:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did it help? What are you using now to get access to the error messages?
Imar
|
|

November 14th, 2009, 02:01 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Imar,
Thank you for checking in.
I've decided to keep my error processing in ASP. I've tested a few more things in SQL Server stored procedure and couldn't get them to work the way I wanted.
Ideally, I'd love to figure it out, but deadlines loom.
Thank you for all your help!
sal
|
|
 |