I've inherited the DTS code below which sends email well but hits an infinite loop every coupla months.While there is limited error checking in the code it doens't alter the flow and the loops run forever.Correcting the loops involves either: (1) exit the loop or (2) terminate the proc(2) sounds easier to me, but I'm not sure how to code an abort proc under DTS. Pretty sure it's simple. Response.End() ???Suggestions appreciated. Code rewrite earns a
.'' This VB Script is scheduled by enterprise manger to run every 5 minutes ' It retrieves POP3 emails and stores them to database ' The ASPPOP3 service must be installed. See: http://www.serverobjects.com/comp/Asppop3.htm'ADO ConstantsConst adCmdStoredProc = &H0004Const adUseClient = 3Const adInteger = 3Const adVarChar = 200Const adVarWChar = 202Const adParamInput = 1Const adDBTimeStamp = 135Const adExecuteNoRecords = &H00000080Function Main()on error resume nextDim i , strEmail1, strEmail2' for ADODim CnxnDim oCmdDim strCnxnDim ClientID, CourseID' Open a connectionSet Cnxn = CreateObject("ADODB.Connection")strCnxn = "Provider='sqloledb';Data Source=sql.wouldyoulike2know.com;Initial Catalog='mydb';User ID=uhhuh; Password=mypassword"Cnxn.Open strCnxnIf err.number <> 0 Then DTSPackageLog.WriteStringToLog "Open Err=" & err.description' for ASPPOP3Dim MailerDim mailMessageID, mailSubject, mailDate, mailFromNameDim mailFromAddress, mailTo, mailBodyText' Loop through all the Email Reader DirectivesSet cmdERD = CreateObject("ADODB.Command")With cmdERD .ActiveConnection = Cnxn .CommandText = "dbo.EMRX_GetDtsDirectives" .CommandType = adCmdStoredProc SET rsERD = .Execute End WithDO WHILE NOT rsERD.EOF ' Retrieve the parameters from this directive recordset intClientID = rsERD.Fields("ClientID").Value intCourseID = rsERD.Fields("CourseID").Value ' open ASPPOP3 connection for this Email Reader Directive Set Mailer = CreateObject ("POP3svg.Mailer") Mailer.RemoteHost = rsERD.Fields("RemoteHost").Value Mailer.UserName = rsERD.Fields("UID").Value Mailer.Password = rsERD.Fields("PWD").Value Mailer.OpenPop3 'Test the POP3 interface Itest = Mailer.MessageCount If err.number <> 0 Then DTSPackageLog.WriteStringToLog "Open Err=" & err.description ' read POP3 mail and insert into database For i = 1 To Mailer.MessageCount If Mailer.Retrieve(i) = True Then mailDate = Mailer.Date mailSubject = Mailer.Subject mailFromAddress = Mailer.FromAddress mailTo = Mailer.Recipients mailBodyText = Mailer.BodyText ' Use Regular Expressions to find 2 email addresses in the Email Message SET objRegExp = NEW RegExp WITH objRegExp ' Create a Regular Expression object .Pattern = "[\w!#$%'*+\-/=?^`{}|~][\w.!#$%'*+\-/=?^`{}|~]+@[A-Za-z0-9-]+\.[A-Za-z0-9.-]+[A-Za-z]" .IgnoreCase = TRUE .Global = TRUE ' Find only first ocurrence of the match END WITH SET colMatches = objRegExp.Execute(mailBodyText) strEmail1 = "" strEmail2 = "" For Each Match in colMatches IF strEmail1 = "" Then strEmail1 = Match.Value ElseIf strEmail2 = "" Then strEmail2 = Match.Value End If Next SET colMatches = Nothing SET objRegExp = Nothing ' Email1 and 2 may be defined at this point Set oCmd = CreateObject("ADODB.Command") With oCmd .ActiveConnection = Cnxn .ActiveConnection.CursorLocation = adUseClient .CommandText = "dbo.EMRX_ProcessRxEmail" .CommandType = adCmdStoredProc .Parameters.Append .CreateParameter("@ClientID", adInteger, adParamInput, , intClientID) .Parameters.Append .CreateParameter("@CourseID", adInteger, adParamInput, , intCourseID) .Parameters.Append .CreateParameter("@xEmailSubject", adVarChar, adParamInput, 255, mailSubject) .Parameters.Append .CreateParameter("@xEmailFromAddress", adVarChar, adParamInput, 100, mailFromAddress) .Parameters.Append .CreateParameter("@xEmailTo", adVarChar, adParamInput, 100, mailTo) .Parameters.Append .CreateParameter("@xEmailBody", adVarChar, adParamInput, 2000, mailBodyText) .Parameters.Append .CreateParameter("@Email1", adVarChar, adParamInput, 100, strEmail1) .Parameters.Append .CreateParameter("@Email2", adVarChar, adParamInput, 100, strEmail2) .Execute ,,adExecuteNoRecords If .ActiveConnection.Errors.Count > 0 Then ' DTSPackageLog.WriteStringToLog "StorePOP3Email Err=" & err.description End If End With Set oCmd = Nothing Mailer.Delete(i) ' Delete this email message from the POP3 server End If Next ' close ASP POP3 connection - this isn't reusable for other POPs Mailer.ClosePop3 Set Mailer = NothingrsERD.MovenextLoop ' (While)' Clean up and ExitrsERD.CloseSET rsERD = NothingSET cmdERD = Nothing' close ADO connectionCnxn.CloseSet Cnxn = NothingMain = DTSTaskExecResult_SuccessEnd Function