2

When connecting to a SQL Server Database in C# I get the query execution time like so:

 SqlConnection conn = new SqlConnection(new SqlConnectionStringBuilder()
                {
                    DataSource = "SERVER",
                    InitialCatalog = "DB",
                    UserID = "USER",
                    Password = "PASSWORD"
                }.ConnectionString);

                conn.StatisticsEnabled = true;

                SqlCommand sqlCommand = new SqlCommand("SELECT * FROM TABLE", conn);

                try
                {
                    conn.Open();

                    sqlCommand.CommandType = CommandType.Text;


                    // execute the command

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

                    var stats = conn.RetrieveStatistics();

                  var milliSecs = (long)stats["ExecutionTime"];
               }
               catch(Execption e){

               }

But I cannot find a similar method to achieve this with a Oracle database.

I have looked at this question but this does the timing on the database not in C#. (I don't have access to edit the queries I will be monitoring).

How can I achieve this? Is there an equivalent function in Oracle.DataAccess library?

Phil3992
  • 1,059
  • 6
  • 21
  • 45
  • 2
    Could you not just make a DateTime before execution and then yet another one after. Then just subtract them and then you got your execution time?.. – Martin M Nov 29 '18 at 14:21
  • 2
    @MartinM Stopwatch class is preferred to measure elapsed times as DateTime.Now has rather low precision: https://learn.microsoft.com/en-us/dotnet/api/system.datetime.now?view=netframework-4.7.2 – BurnsBA Nov 29 '18 at 14:26

0 Answers0