Structured Exceptions in ADO.NET 2.0/Yukon

Published Thu, Apr 21 2005 1:47 | William

Well, tonight I just pretty much finished up the first chapter of one of the two books I'm working on .  Anyway, one of the Chapters I'm wriitng is on the T-SQL Enhancements and I got to wondering.  How are Exceptions that you raise in T-SQL handled from the client side.  My first guess was that  “It depends” but that Print Statements would be treated just as they are currently....  Ok, here's the test.  First the procedure:

ALTER PROCEDURE dbo.usp_TestProc
AS BEGIN TRY
  DECLARE @Value DATETIME
  SET @Value = 'cuckoo'
  PRINT'Cuckoo, Cuckoo'

END
TRY
  BEGIN CATCH
  Print 'Catch Cuckoo Exception'
END CATCH
RETURN
 
As you can see, I'm intentionally causing an exception condition by converting the literal 'cuckoo' to a DateTime. Now for the code:
SqlConnection cn = null;
private void Form1_Load(object sender, EventArgs e)
{
cn =
new SqlConnection(@"Data Source=adamlaptop\cuckoobird;Initial Catalog=Cuckooz;Integrated Security=SSPI;" );
cn.InfoMessage +=
new SqlInfoMessageEventHandler(MessageHandler);
cn.Open();

SqlCommand cmd = new SqlCommand("usp_TestProc", cn);
cmd.CommandType =
CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
cn.Close();
}
private void MessageHandler(object sender, SqlInfoMessageEventArgs args)
{
MessageBox.Show(args.Message)
};

And just as expected, 'Catch Cuckoo Exception'..........

Comments

# William said on April 21, 2005 1:47 PM:

Quite exciting. What are the requirements on the database side for this to work?

# William said on April 21, 2005 2:38 PM:

Sahil - other than using Yukon there really isn't anything server side. That's just straight T-SQL That I used with Yukon.

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications