PC Review


Reply
Thread Tools Rate Thread

Capturing return value from SQL Server's stored procedure

 
 
=?Utf-8?B?UGF0cmljaw==?=
Guest
Posts: n/a
 
      29th Jul 2005
Using Microsoft.Practices.EnterpriseLibrary.Data, how do I capture the return
value from executing a stored procedure on SQL Server 2000 (i.e., how could
I tell the Stored Procedure did not return 0 [indicating failure] or that a
transaction the stored procedure begun had been rolled back):

No exceptions were thrown from the following when -1 was returned and
transaction rolled back:
Database db = DatabaseFactory.CreateDatabase();

string sqlCommand = "uspCreator";
DBCommandWrapper creatorCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);

db.ExecuteNonQuery(creatorCommandWrapper);
 
Reply With Quote
 
 
 
 
David Browne
Guest
Posts: n/a
 
      29th Jul 2005

"Patrick" <(E-Mail Removed)> wrote in message
news:1B7FF39F-7ECE-4B70-84B3-(E-Mail Removed)...
> Using Microsoft.Practices.EnterpriseLibrary.Data, how do I capture the
> return
> value from executing a stored procedure on SQL Server 2000 (i.e., how
> could
> I tell the Stored Procedure did not return 0 [indicating failure] or that
> a
> transaction the stored procedure begun had been rolled back):
>
> No exceptions were thrown from the following when -1 was returned and
> transaction rolled back:
> Database db = DatabaseFactory.CreateDatabase();
>
> string sqlCommand = "uspCreator";
> DBCommandWrapper creatorCommandWrapper =
> db.GetStoredProcCommandWrapper(sqlCommand);
>
> db.ExecuteNonQuery(creatorCommandWrapper);


Checking the return code of stored procedures is for server side invocation,
and is simply a workaround for the fact that when a stored procedure calls
another stored procedure, it cannot capture the error message. Client code
should detect failure from the error message.

So the stored procedure should indicate failure with both a return code, and
an error message. If no error message is currently being generated on
failure, then you should generate one using RAISERROR in the stored
procedure.

David



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      30th Jul 2005
Hi Patrick,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the return value from
the executing stored procedure. If there is any misunderstanding, please
feel free to let me know.

You can add another SqlParameter object to the parameter collection and set
its Direction property to ParameterDirection.ReturnValue before executing.
After execution, you can check the value of this parameter to get the
return value.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
ADO: how to execute SQL Server stored procedure and get return val jrsmoots Microsoft Access VBA Modules 1 23rd Jun 2009 08:12 AM
Capturing SQL Stored Procedure Return Codes Rod Behr Microsoft Access VBA Modules 4 7th Mar 2008 03:49 PM
Need help: Call server side Stored Procedure and get the return va =?Utf-8?B?ZGF2aWQ=?= Microsoft ASP .NET 3 20th Oct 2006 05:09 PM
Checking permission rights using SQL Server Stored Procedure and return values Scott Microsoft Access Form Coding 0 1st Oct 2006 03:22 PM
Capturing Stored Procedure return value Mike P Microsoft C# .NET 2 4th Oct 2004 01:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:09 PM.