Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log my SQL calls in Visual Studio 2013?

I used to have it working great. I would just select the output window and all the calls would be logged and output. But then I reinstalled VS 2013 and now I see nothing.

Please note this is a built in feature. Not something I used to do with debug calls or anything in my code.

I have been doing this for over a year now and just cannot figure out what option I selected to make it happen. Can anyone remember how to do this?

like image 619
Alan2 Avatar asked Apr 11 '15 14:04

Alan2


People also ask

How do I view SQL data in Visual Studio?

In Visual Studio, make sure that SQL Server Object Explorer is open. If it is not, click the View menu and select SQL Server Object Explorer.

How do I run SQL code in Visual Studio code?

Create or open a SQL file The mssql extension enables mssql commands and T-SQL IntelliSense in the code editor when the language mode is set to SQL. Select File > New File or press Ctrl+N. Visual Studio Code opens a new Plain Text file by default.


2 Answers

Starting with EF 6.0 you would do

using (var context = new BlogContext()) 
{ 
    context.Database.Log = Console.Write; 
    // Other code here... 
}

From here: Logging and Intercepting Database Operations

like image 154
tomsv Avatar answered Oct 19 '22 23:10

tomsv


For VS2013 Pro, I can't get the query to the output window, but you can make it log to the Message pane of the query results. Is this what you're referring to?

Tools >
   Options > 
       SQL Server Tools > 
           Transact-SQL-Editor > 
               Query Results > 
                   Results to Grid

Check 'Include the query in the result set'enter image description hereenter image description here

like image 37
InbetweenWeekends Avatar answered Oct 20 '22 01:10

InbetweenWeekends