Last post Feb 23, 2015 05:15 AM by skliz4rel
Feb 20, 2015 08:54 AM|skliz4rel|LINK
I have a query that collect the Name of a country from my country Table. The country table contains all countries in the world.
But unfortunately I keep experiencing the time out error every time. Please what if I have a table of 1 million records is this what EF would do on real live production server. Or is there something that I am missing out.
I would paste my db code below
string Name = "";
Line 54: Name = this.context.Countrys.Where(item => item.CountryID == CountryID).Select(item => item.Name).FirstOrDefault<string>();
Line 56: return Name;
I have google on this and most people suggest using this command below
But how do I get to use this command cos I dont know how.
My second question, on any of my tables that would have lot of records when I launch my project life. Do I have to take this precautions to prevent an error like this during life operations.
Feb 20, 2015 09:00 AM|Lokesh B R|LINK
try this query
var query = this.context.Countrys.Where(item => item.CountryID == CountryID).FirstOrDefault();
if (query != null)
string name = query.FirstOrDefault().Name;
1. I don't think so since you have the WHERE condition, you will get the result quickly.
The above query is something like
SELECT * FROM Countries WHERE CountryID = 100
try executing the above query in SQL Management Studio and check the time taken.
Feb 20, 2015 09:14 AM|skliz4rel|LINK
Thanks alot, So when exactly do we need to use Stored Procedures.
Is it when I am collecting very large recordset from the db ?
Is is when I am doing join queries too ?
I would try your query in studio ?
Feb 20, 2015 09:17 AM|Lokesh B R|LINK
So when exactly do we need to use Stored Procedures
yes, try the SQL query in SQL Management studio and see the performance.
Feb 20, 2015 10:14 AM|skliz4rel|LINK
I have tried the query. It runs in one seconds. The wait time out error is usually experienced after I do a rebuild of my project.
At a first time launch. I sometimes get the error. Though not always.
Feb 20, 2015 10:26 AM|skliz4rel|LINK
I have been able to read up on Stored Procedures. It is quite interesting. But is there a way I can seed my database such that my Store Procedures are created for me each time I seed my db. Since I am using Code First Approach in my App development.
Feb 23, 2015 01:34 AM|Sherwin Zhao|LINK
Thanks for you post.
You have tried the query in SQL Management Studio. It just cost one second. But some time you still received the time out error. There is another possibility, maybe other operation was inserting/updating data to this table. So this table was locked until
operation end. So you could try to trace your sql, is there code have many insert/update operation.
Hope this can be helpful to you.
Feb 23, 2015 05:15 AM|skliz4rel|LINK
Well I think you have a strong point here. Fortunately I have stopped the time out error. I noticed the time out error only occurs after a first time rebuild. This Table contains a lot of datas (All countries in the world.).
Please NOTE that when you load a project with EF after a first time rebuild, it takes a while for the project to launch fully.
So I felt possibly the time out comes were project is trying to make a first time set up. So simply converted the module to Store procedure. Since they have a shorter execution time. To speeding up db execution.
Since I have not experienced this error again.
Well I am not inserting anything into the table, So nothing should keep it locked. It just the waiting time for a first time setup that possibly causing it.