1

I have few oledb connections like this:

try
{
    OleDbConnection Connection8;
    using (Connection8 = new OleDbConnection("Provider=MSDAORA.1;Data Source=DATABASE:1521/orcl;Persist Security Info=True;Password=PASSWORD;User ID=USERNAME;"))
    {
        string sqlQuery = "select * from TABLE";

        using (OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, Connection8))
        {
            Connection8.Open();
            DataTable dt = new DataTable();
            cmd.Fill(dt);
            GridView5.DataSource = dt;
            GridView5.DataBind();
            v8 = 1;
            Connection8.Close();
        }
    }
}
catch (Exception)
{
    v8 = 0;
}

Some connections waiting so much, but I can't know which one.

How can I log or see query time for every connection? Any suggestion for that? Thank you.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
onur
  • 5,647
  • 3
  • 23
  • 46
  • 1
    You can use a profiler during debugging sessions. Or is this a production issue? New Relic might be helpful for example. However a 'best' solution i to broad. Ofcourse in-code like stopwatch can work but this sounds unwise for troubleshooting. (Exception: logging) – Myrtle Jan 26 '16 at 15:28
  • Keep the connection pooling in mind ;-) – Jef Patat Jan 26 '16 at 15:33

3 Answers3

3

You can use Stopwatch:

var stopwatch = new Stopwatch();
DataTable dt = new DataTable();
stopwatch.Start();
Connection8.Open();
cmd.Fill(dt);
stopwatch.Stop();

var timeElapsed = stopwatch.ElapsedMilliseconds;

Notice here in sample I've shown time to open connection will be included in measured time. If you don't need it and want "pure" query execution time - then just change the order od lines where connection being opened and stopwatch started.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
0

I don't know if this will work because you are using a OleDbConnection but one thing you may be able to do is in control panel open the "Odbc Administrator" (Be sure to check if you want 32 bit or 64 bit) there is a "Tracing" tab you can turn on, that gives you a log file of all ODBC requests that are processed.

enter image description here

But remember, like I said, because you are using a OleDbConnection it may not log anything.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
0

I've used Glimpse in the past, might be as well useful for you:

http://getglimpse.com/

Swag
  • 2,090
  • 9
  • 33
  • 63