Click here to Skip to main content
15,042,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get execution time of a sql query in a text file?
Posted
Updated 29-Sep-10 1:39am
v2

VB
TimeSpan Duration; 
DateTime StartTime = DateTime.Now
'Call the database here and execute your SQL statement
Duration = DateTime.Now.Subtract(StartTime)
Console.WriteLine(String.Format("Query took {0} seconds", Duration.TotalSeconds.ToString()))
Console.ReadLine()


Please vote and Accept Answer if it Helped.
   
Firstly, I would ask you to post the question bit clearly. What is the purpose of recording the execution time? Is it to be recorded by the application to keep log or do you want to check the performance and execution time of few slow running queries.

Assuming, you need it to check the performance, I would suggest you to use SQL Profiler, with that you would get detailed execution plan. Showplan will allow you to get the desired result.
   

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