ReTry——访问数据时失败,等待后重试

        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Double)
<
WebMethod() >  _
        
Public   Function  ReTry()  As   Integer

            
Dim  aDS  As   New  DataSet       
            
Dim  aSql  As   String
            
Dim  aRet  As   Integer
            
Dim  CheckFlg  As   Boolean
            
Dim  aRetry  As   Integer
            
Dim  aWait  As   Integer
            
Dim  OraDa2  As  OleDb.OleDbDataAdapter

            
'等待时间
            aWait  =  LockWaitTime
            '重试次数
            aRetry  =  LockRetryMax

            OpenOraDatabase()

            OraTrans 
=  OraConn.BeginTransaction()
            OraCmd.Transaction 
=  OraTrans
            
Try
                CheckFlg 
=   True
                
For  i  =   1   To  aRetry
                    
Try
                        
'执行失败
                         If  CheckFlg  =   False   Then
                           
'等待
                             Call  Sleep(aWait  *   1000 )
                        
End   If
                       
'指定SQL语句
                        aSql  =  “”
                        OraCmd.CommandText 
=  aSql
                        OraDa2 
=   New  OleDb.OleDbDataAdapter(OraCmd)
                        
' 打开记录集
                        OraDa2.Fill(aDS,  " TableName " )
                        
If aDS .Tables( " TableName " ).Rows.Count  =   0   Then
                            aRet 
=   0
                        
Else
                            aRet 
=   1
                        
End   If
                       
'执行成功
                        CheckFlg  =   True
                    
Catch  ex  As  Exception
                        CheckFlg 
=   False
                    
End   Try
                    '执行成功退出循环
                     If  CheckFlg  =   True   Then
                        
Exit   For
                    
End   If
                
Next  i

                
If  CheckFlg  =   False   Then
                    aRet 
=   2
                    
Return  aRet
                    
Exit Function
                
End   If

                
If  aRet  =   1   Then
                    
                
End   If
               
                OraTrans.Commit()
                aRet 
=   1
            
Catch  ex  As  Exception
                OraTrans.Rollback()
                aRet 
=   0
                
Return  aRet
            
Finally
                CloseOraDatabase()
            
End   Try

            
Return  aRet

        
End Function

你可能感兴趣的:(try)