Click here to Skip to main content
15,889,759 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a Windows application using LINQ to SQL with a database that's locked down (so that I can't use SQL Server Profiler on it).

I'd like to see the actual SQL text that the application is sending; what's the easiest way to see the SQL text sent using just the Windows application (and not the database)?
Posted

1 solution

Try as below code:
TestDataContext testDataContext = new TestDataContext();

IQueryable<employee> myQuery =
  from emp in testDataContext.Employee
  where emp.EmployeeId == 123
  select emp;

string sqlCommand = testDataContext.GetCommand(myQuery).CommandText;</employee>
 
Share this answer
 
v11
Comments
RaisKazi 5-Aug-11 14:59pm    
Apologies for un-formatted code. I tried to format it, but its does not seems to reflecting.
jesarg 5-Aug-11 15:50pm    
That works great; thanks.
RaisKazi 5-Aug-11 16:23pm    
Perfect. Cheers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900