简体   繁体   中英

Linq to Sql TImeout issues

I have a method to pull a user's information using linq to sql classes. The method executes three queries using linq statements that call existing stored procs. Here is an example of how I am laying out my linq statements.

            using (var db = new TestDataContext(connection)))
            {
                var user = db.proc_UserInfo(userId);

                foreach (var x in user)
                {
                    string FullName = x.FirstName + " " + x.LastName;
                    string Address = x.Addr1;
                    string City = x.City;                        
                }
            }

This method is called through a web api controller which fires from a jquery ajax request. It works fine but when I put some load on it by hastily changing the dropdown list full of users that makes the ajax request I notice if I can do it fast enough it seems like the batch of queries going to the db are canceled and the calls are suspended for a few minutes the next queries made timeout and return null objects. One thing to note these queries are not returning but a few rows of data. I'm still trying to figure out what is going on and am open to suggestions. Thanks in advance.

First of I think people may need a little more information. Database type I assume is SQL Server but you havent listed a version yet. In any case, it may be a few things. Remember AJAX calls are running as a http request / post so there may be IIS timeouts or other various IIS limitations there. Also, are your calls asynchronous etc. Jquery has some settings you may want to verify. Table locking is SQL Server is also a possibility. Also check your browser ram / w3wp usage to make sure its not running out of resources.

First off I suggest running SQL Profiler to verify whats going on, then check the execution plans of those queries. If theres a large amount of data, you may need some indexing.

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