简体   繁体   中英

Very long request time VS2010

I have at small web-application that get some data from a SQLdb in Visual Studio 2010. When i try to display this, using a simple dropdownlist it takes around 15 sec the first time just after compilation and then after that 5 sec every request. I use a LINQ connection to db and a repeater to print everything out. It´s four columns and around 50 rows, so not so mutch data. It doesn´t matter if i try take 10 rows, same response time.

We have tested the same thing on another computer with VS2008 installed and the time was like 0.1 sec or something like that. I use .NET 3.5 and have installed all the latest updates (SP1 and so).

If i look at the trace i see it takes time at these rows in my code:

var cust = dbContext.Customers
    .Select(c => new
    {
        c.customerID,
        c.Email
    }).Take(10);

repeater.DataSource = cust;
repeater.DataBind();

Anybody know what could be taking som mutch time?

Regards Daniel

I have tried this other aproach:

SqlConnection connection = new SqlConnection(connectionString);

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connection;
        cmd.CommandType = CommandType.Text; //default

        cmd.CommandText = "SELECT Email FROM Customer";

        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();

It takes just as long.. there must be some other more fundamental problem than the code to call the db i think?

Some more information: I did som trace, this is first time page is loaded:

Begin Raise ChangedEvents   0,00219604937555932 0,000014
After repeater has printed  15,8138335259613    15,811637
End Raise ChangedEvents 15,8138801733289    0,000047

Second time:

Begin Raise ChangedEvents   0,00219604937555932 0,000014
After repeater has printed  5,25090396258066    5,248825
End Raise ChangedEvents 25095106283536          0,000047

What´s happening at ChangeEvents?

Get the actual SQL being generated by LINQ, copy-paste it to your database management tool and look at the execution plan to identify potential performance issues.

You can see the actual SQL by using Log property of the data context. In a console application, you can do this:

dbContext.Log = Console.Out;
// ...

Or, write the SQL to file like this:

using (var writer = new StreamWriter("sql.log")) {
    dbContext.Log = writer;
    // ....
}

Also, it might be worth adding ToList() or ToArray() at the end of your LINQ expression, just to make sure it is not unintentionally re-executed.

I have no idee what i did to make it work.. just kept on doing stuff at other places in the code and updated latest windows update.. hmm.. now it work like a charm, must be a bug in VS2010?? Thanks for all suggestions though, learned some great stuff!

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM