Solved

SQL Server view query slow until refreshed

Posted on 2013-01-23
1
298 Views
Last Modified: 2013-01-27
I have a view that starts performing slowly when queried via a C# program using LINQ to SQL.  The equivalent query executed in management studio performs fine.  By equivalent I mean that the SQL code that is created by LINQ to SQL is pasted into management studio and executed.

After I run sp_refreshview then the LINQ to SQL C# program performs as well as running the query in management studio.  There have not been any changes to the schema during this period.

Any ideas?
0
Comment
Question by:codebozo
1 Comment
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 38812485
I suggest adding "OPTION (RECOMPILE)" to any SELECTs from this view and seeing if that solves the problem.

Sounds like you have the equivalent of the "parameter sniffing" issue for stored procs.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question