Hilton Giesenow's Jumbled Mind

the madness that is...

News

This is my little spot in cyberspace where you will find a collection of random (but mostly software-related) thoughts and ideas that are frightening in their shining brilliance (or something like that ;->).
 
Please enjoy your stay and feel free to Contact Me.
 
Microsoft MVP
 
I'm a Shoe Circus Member!

.Net Links

BlogRoll

Misc. Links

Syndication

Displaying LINQ To SQL's Actual SQL Queries in your ASP.NET Page

I've made use of the Log property on the DataContext class in a few of my LINQ To SQL posts. Usually, it's been in a console application, and we're just looking at the SQL output in the console window, so we use:

dataContext.Log = Console.Out;

However, in a web application, this won't help. If you want to see the output of your SQL directly in the page, you can use:

System.IO.StreamWriter httpResponseStreamWriter = new StreamWriter(HttpContext.Current.Response.OutputStream);
dc.Log = httpResponseStreamWriter;

As to whether it's a good idea to display this directly into the output (effectively Response.Write) - that's up to you ;->. As an alternative, as Log is just expecting a TextWriter, you could use a StringBuilder with a StringWriter, and then display it's output in a label.

For a more robust solution, Kris Vandermotten has a sample on Sending the LINQ To SQL log to the debugger output window.

Posted: Jul 16 2008, 10:54 AM by hiltong | with 1 comment(s)
Filed under: ,

Comments

Hilton Giesenow's Jumbled Mind said:

I posted recently on logging the LINQ To SQL output to the ASP.NET response stream . Damien Guard has

# August 8, 2008 9:03 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: