views:

35

answers:

1

Hi, is it possible to access the InfoMessage event handler in a Linq2SQL data context? All of our code uses these messages to display useful information to the end user and since moving to Linq2SQL I cannot figure out how to show these messages. I have checked the connection object of the data context as well as the classes properties with no luck so I'm wondering if it is possible.

Thanks in advance.

A: 

You need to simply cast the context's connection to a SqlConnection and then hook up your info message handling routine:

YourDataContext ctx = new YourDataContext();

SqlConnection con = (cufe.Connection as SqlConnection);

if(con != null)
{  
    con.InfoMessage += new SqlInfoMessageEventHandler(con_InfoMessage);
}

and then of course implement that SqlInfoMessageEventHandler in your code.

marc_s
Works great thanks :)
Paul Oakham
@Paul Oakham: ok, so if it works great and thus solved your problem, please **accept** this answer - click on the big checkmark to the left of the question.
marc_s