Skip to content
Advertisement

How to avoid Sql Query Timeout

I have RO access on a SQL View. This query below times out. How to avoid this?

select  
  count(distinct Status)  
from 
  [MyTable]  with (NOLOCK)
where 
  MemberType=6

The error message I get is:

Msg 121, Level 20, State 0, Line 0

A transport-level error has occurred when receiving results from the server (provider: TCP Provider, error: 0 – The semaphore timeout period has expired.)

Advertisement

Answer

Although there is clearly some kind of network instability or something interfering with your connection (15 minutes is possible that you could be crossing a NAT boundary or something in your network is dropping the session), I would think you want such a simple?) query to return well within any anticipated timeoue (like 1s).

I would talk to your DBA and get an index created on the underlying tables on MemberType, Status. If there isn’t a single underlying table or these are more complex and created by the view or UDF, and you are running SQL Server 2005 or above, have him consider indexing the view (basically materializing the view in an indexed fashion).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement