Wrox Programmer Forums
|
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
 
Old November 13th, 2009, 03:16 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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..
 
Old November 13th, 2009, 04:32 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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!
 
Old November 13th, 2009, 04:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 13th, 2009, 04:57 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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.
 
Old November 13th, 2009, 05:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 13th, 2009, 05:11 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
 
Old November 13th, 2009, 05:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 13th, 2009, 05:51 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thank you very much for your time!

have a wonderful weekend.

sal
 
Old November 14th, 2009, 04:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did it help? What are you using now to get access to the error messages?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 14th, 2009, 02:01 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Stored Procedure doug SQL Server 2000 2 February 22nd, 2005 03:04 PM
error building dynamic sql in stored procedure paaf64 SQL Server 2000 3 October 6th, 2004 03:08 PM
Sql server Stored procedure ranakdinesh BOOK: Professional C#, 2nd and 3rd Editions 2 May 29th, 2004 12:08 AM
dymanic sql vs stored procedure prox_lae Oracle 0 February 19th, 2004 10:30 PM
SQL Stored Procedure... babloo81 SQL Server ASP 1 December 8th, 2003 03:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.