onur
onur

Reputation: 6365

How can I log query time?

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.

Upvotes: 1

Views: 869

Answers (3)

Swag
Swag

Reputation: 2140

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

http://getglimpse.com/

Upvotes: 0

Scott Chamberlain
Scott Chamberlain

Reputation: 127563

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.

Upvotes: 0

Andrey Korneyev
Andrey Korneyev

Reputation: 26846

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.

Upvotes: 3

Related Questions