Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_database_setup thread: Detect SQL Timeout with ASP and issue Rollba- ck


Message #1 by Eli Schilling <eschilli@t...> on Wed, 24 Oct 2001 15:09:14 -0700
I just found this and wanted to pass it around.  I run several SQL

procedures within ASP that take a few minutes to run and with this snippet

of code you can detect the current timeout for SQL and even increase it as

you need:



Dim colErrs, objError, timeout, adoConn, adoCmd 

timeout=False 

Set adoConn = Server.CreateObject("ADODB.Connection") 

adoConn.CursorLocation = adUseClient 

adoConn.Open Session("UserConnStr") 

adoConn.IsolationLevel = adXactReadUncommitted 

'The next line starts a transaction 

adoConn.BeginTrans 

Set adoCmd = Server.CreateObject("ADODB.Command") 

'I added this to give the command 45 seconds to execute. 

adoCmd.CommandTimeout = 45 

adoCmd.ActiveConnection = adoConn 

adoCmd.CommandText = "sproc_RecalculateQuantities" 

adoCmd.CommandType = adCmdStoredProc 

adoCmd.Execute 

Set colErrs=adoConn.Errors 

If adoConn.Errors.Count <> 0 then 

     For Each objError In colErrs 

         'This is the error number for a timeout. 

         If objError.Number=-2147217871 Then 

             adoConn.RollbackTrans 

             Response.Write "The query timed out before finishing.  Please

try again." 

             timeout=True 

             adoConn.Errors.Clear 

             Exit For 

         End If 

     Next 

End If 

Set adoCmd = Nothing 



If Not timeout Then 

    adoConn.CommitTrans 

End If 

adoConn.Close 

Set adoConn = Nothing 





Cheers!!!

-Eli Schilling


  Return to Index