Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedures returning errors...

Status
Not open for further replies.

TPetersonFlorida

Programmer
Aug 8, 2003
76
US
I have an ASP.Net application that calls various stored procedures. I have not yet figured out how to access an error that is raised in the stored procedure from the calling application. Any help is appreciated!!!

Thanks!
 
If the SPROC causes an error, an SqlException is thrown. Use a Try/Catch block to trap that error and display the results.

Code:
try
{
    mySqlConnection.Open();
    mySqlCommand.ExecuteNonQuery(); // or whatever...
}
catch(Exception x)
{
    Trace.Warn(x.ToString());
}
finally
{

    mySqlConnection.Close();
}

If you have Trace enabled in your application, any errors will show up in red in the Trace output if an exception occurs there. Note that the finally block will always execute even if an exception occurs, so it's a good place to close your connection.

Greetings,
Dragonwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top