With respect to performance tuning, I would like to find out the number of DB calls each page is making. Also, the stored procedures and queries that is executed. I'm using Asp.net and SQL Server 2008. In some places we have directly written the query in C# insead of calling SP.
I tried using SQL Profiler. In that, under Event if I select SP, I'm able to trace the SP calls. But what about the queries that are direcly called in C#. How can I trace that.
Kindly let me know how this can be done or if there is a better tool to find this out.
Thanks in advance.
Use SQL Profiler to create a trace that logs these events:
RPC:Completed
SP:Completed
SP:StmtCompleted
SQL:BatchCompleted
SQL:StmtCompleted
See How Can I Log and Find the Most Expensive Queries?
When you open a new trace you can select the template TSQL Which will then include the event SQL:BatchStarting that will show you the queries as well
Related
I was wondering if there is there a tool or a way to view which statements cause a block/lock and which objects would be affected? I know about sp_who and sp_who2, but those only work while the system is running.
For example, I know running this:
UPDATE myTable SET col1 = 'something'
Will put a lock on "myTable", but there are more complex scenarios (like nested procs and triggers) that would be more difficult to identify.
I was hoping for tool like the "Actual Execution Plan" built-into SSMS, but other tools, queries will suffice
Thanks all
You can refer this blog and follow the different ways to identify the blocks:
sp_who2 System Stored Procedure
sys.dm_exec_requests DMV
Sys.dm_os_waiting_tasks
SQL Server Management Studio Activity Monitor
SQL Server Management Studio Reports
SQL Server Profiler
Also check: Different techniques to identify blocking in SQL Server
You can use SQL Activity Monitor (right click on the SQL instance in SSMS) to get a list the number of current locks etc and you can use the 'Task State' column of the 'Processes' panel in there to see currently running statements which will tell you if things are blocking.
These all focus on activities which are currently executing though, so I'm not sure this will be what you want.
I have to debug a long running SQL Server stored procedure which dynamically builds and executes queries at runtime. I want to run a trace so I can see all of the individual pieces of SQL that are executed.
Which events will provide that level of detail?
I've been advised to use Stored Proc: RPC Completed; Batch Completed and Batch Started. But that's only bringing back the initial execution statement. ie. literally "exec MyStoredProcName".
Any ideas?
Thanks In Advance.
I had a program using SQLconnector to connect to MS SQL 2012, I want know SQL query execution time. I am aware there is a SQL Server Profiler, but I can't configure it correctly to capture any query execution time. I am also aware that I can add timer within program but i can not change code easily.
All advice welcome. thanks
AFAIK SQLConnector is for MySQL, so I don't understand how you can work with SQLServer 2012.
If you need profiling in SQLServer - there is nothing better than SQL Server Profiler.
I can't configure it correctly to capture any query execution time
It must be easy:
Event Selecion - you need SQL:Stmt Completed (uncheck everything else). You need to select duration.
Column Filters - create filter by Login Name (make special login if you need it), TextData, Spid (if you can figure out how to obtain it)
This is not supported by default but you can do this using several techniques depending on what are your needs.
Do you need to capture every statement including SELECT? If yes then I suggest you still use SQL Server Profiler or SQL Server Traces
If you only need to capture DML statements (excluding SELECT) you can try setting up triggers on tables you want to audit.
There are also DDL triggers that can help you catch DDL statements (as far as I know there is no way to capture all DDL statements using DDL triggers).
So, there are many options here but it all depends on what are your needs.
I have this c# web app that relies heavily on two dll files that i can't see nor edit. The rest of the app is visible and editable.
The app generates SQL exceptions, and i would like to see the queries sent from the DLLs. Is there a way to do that?
You can use SQL Profiler to see the queries that goes to your database.
For SQL Server 2005/2008 Express you can try AnjLab's SQL Profiler.
Another way to see what is running is SP_WHO2 'active' combined with DBCC INPUTBUFFER(SPID) or query the [sys.dm_exec_requests].
The SQL Profiler mentioned above is the preferred method.
I run a site at localhost and I would like to see which queries are executed.
I've seen that some pages execute a lot of queries (eg 107) and I would like to see which are all these,as I think they're a lot..
(I know how many queries are executed, as the queries are executed through a function which also stores at a global value the number of queries)
Is it possible?
Thanks!
Modify the function that you use to execute queries, so that it will log them into a file or just output them at the bottom of the page for instance.
There is no tool or (built-in) function that would tell you what was executed on some specific request.
You can trace a mysql database as described at this link.
Turn on the MySQL general query log. Quite useful during development, it will show you literally everything that your server is doing.
As such, I wouldn't recommend enabling it on a production server (at least not for long).