Friday, February 1, 2013

Silverlight LinqToSql SQL Tracing

Silverlight LinqToSql SQL Tracing

I am using Silverlight 5.0 with LinqToSQl and WCF RIA Services in my project. I am trying to figure out how to log Traces of the underlying SQL Statements (to Sql Server), either in debug mode, or log it to a console window, or file. I would need this for all CRUD operations.

All samples online point out to the DataContext.Log property, but I always find its value to be "Nothing", and also, I cannot get to it from the Client side of the project. If possible, I am planning to have a UserInterface to display the actual SQL Statements before proceeding to either retrieve or save data. This will be mainly for debugging purposes.

Is there a way to view the underlying SQL Statements from the client end (using a break point and checking the values in the Immediate window, or something like that)

Thanks.

Answers & Comments...

Answer: 1

If you want to log the sql statements executed by your DataContext you need to assign a TextWriter to the property Log of your DataContext.

Null is the default value of Log for the DataContext and therefore is logging of commands disabled.

To log the sql statements to the console, you can assign Console.Out to the property.

db.Log = Console.Out; 

If you want to write the log to a file you can assign a StreamWriter to the property.

by : Jehofhttp://stackoverflow.com/users/83039




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog