Timeout Error

Hi,

When try to execute below statement, i am getting timeout error some times and this is written to execute as a script, so i can not determine at which point it gets timed out.

Declare @ID BIGINT;  
  Select @ID = Max(PMTDID) from TBLT_PaymentModeTransferDetail with (NOLOCK)  
  if @Id IS NOT NULL  
  BEGIN  
   DBCC CHECKIDENT(TBLT_PaymentModeTransferDetail, RESEED, @ID)  
  END  
  ELSE If @ID IS NULL AND Ident_Current('TBLT_PaymentModeTransferDetail') <> (Select IDENT_SEED(TABLE_NAME) AS Seed from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TBLT_PaymentModeTransferDetail')  
  BEGIN  
   Set @ID = 1404  
   DBCC CHECKIDENT(TBLT_PaymentModeTransferDetail, RESEED, @ID)  
  END  
  ELSE IF 1404 IS NOT NULL AND Ident_Current('TBLT_PaymentModeTransferDetail') = (Select IDENT_SEED(TABLE_NAME) AS Seed from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TBLT_PaymentModeTransferDetail')  
  BEGIN  
   Select @ID = (IDENT_SEED(TABLE_NAME) -1) from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TBLT_PaymentModeTransferDetail'  
   DBCC CHECKIDENT(TBLT_PaymentModeTransferDetail, RESEED, @ID)  
  END  

Thanks,

Rajnikant

April 27th, 2015 7:55am

SQL Server does not timeout a query.  Your caller must be timing out.  How are you calling this script?

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 8:05am

Hi,

Thanks for the reply.

I am calling it from .net application, which have connection string and connection timeout has not been set.

Thanks,

Rajnikant

April 27th, 2015 8:11am

Please see:

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Also see the "Note" section under Remarks.

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 8:15am

If you can accept that the query runs for some time, change the CommandTimeout property on the Command object to 0, which means "wait forever".

If are impatient and you think that the scriptis taking too long time, I would suspect that you are victim to blocking. Use sp_who2 to find out. If you see a value in the Blk column, this spid is blocking the spid on this line.

April 27th, 2015 8:18am

SQL server throws timeout error when any one of the following causes occurs

before setting up connectionTimeout = 0 in your code (not recommend) or Connection Timeout = 0 in connection string

try to run

EXEC sp_updatestats on your database to update stats. 

Cause

Resolution

Server name was typed incorrectly.

Try again with the correct server name.

The SQL Server service on the server is not running.

Start the instance of SQL Server Database Engine.

The TCP/IP port for the Database Engine instance is blocked by a firewall.

Configure the firewall to permit access to the Database Engine.

Database Engine is not listening on port 1433 because it has been changed, or because it is not the default instance, and the SQL Server Browser service is not running.

Either start the SQL Server Browser service, or connect specifying the TCP/IP port number.

The SQL Server Browser service is running but UDP port 1434 is blocked by a firewall.

Either configure the firewall to permit access to the UPD port 1434 on the server, or connect specifying the TCP/IP port number.

The client and server are not configured to use the same network protocol.

Using SQL Server Configuration Manager, confirm that both the server and the client computers have at least one enabled protocol in common.

The network cannot resolve the server name to an IP address. This can be tested using the PING program.

Fix the computer name resolution problem on your network or connect using the IP address of the server. This is not a SQL Server problem. For assistance, see your Windows documentation or your network administrator.

The network cannot connect using the IP address. This can be tested using the PING program.

Fix the TCP/IP problem on your network. This is not a SQL Server problem. For assistance, see your Windows documentation or your network administrator.

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 11:50am

SQL Server does NOT send a timeout.  .NET reports a timeout for those reasons. 

The reasons you posted are caused by CONNECTION timeout, not COMMAND timeout.  The actual error would indicate which is causing the issue.

April 27th, 2015 3:05pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics