[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Detecting "raiserror" from stored procedure

Mike Helbert

12/4/2002 8:44:00 PM

I have an application that runs a stored procedure in
Sybase. I originally used the OleDb classes, but because
of flakiness in the Sybase OLE DB driver, I'm looking at
switching to ODBC. It seems to work OK, except that when
the stored procedure does a "raiserror", there is no
exception thrown. With OleDb, this would throw an
OleDbException with the text passed to raiserror in the
Message property (very easy to handle). I tried this
using SQL Server and got the same response (no
exception). Is there a way to either make it throw an
OdbcException, or check after the stored procedure returns
to check for errors?

SP (same syntax in SQL Server and Sybase):
create proc Test
@SuccessFlag int output
as
select @SuccessFlag = 1
raiserror 17001 "Error from SP"
return
go

C#:
OdbcConnection cn = new OdbcConnection("DRIVER=SQL Server,
yadayadayada...)
OdbcCommand cmd = new OdbcCommand("{call junk.dbo.Test
(?)}", cn);
cmd.CommandType = CommandType.StoredProcedure;
OdbcParameter parm = cmd.Parameters.Add
("@SuccessFlag",OdbcType.Int);
parm.Direction = ParameterDirection.InputOutput;
parm.Value = 0;

try
{
cn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// Doesn't get here using ODBC
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}

1 Answer

Torben Christensen

12/10/2002 5:24:00 PM

0