Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 28th, 2005, 03:38 PM
affu2000 affu2000 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 13 affu2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 25 sec
Reputation Power: 0
Question Urgent: Error Log

The following script is run to send emails to candidates applying for a position.

I want to log any kind of errors that take place during this process and save them in a separate file (like a .log or .dat)

Please help me.

Code:
' VBScript source code
Set db = CreateObject("ADODB.Connection")
set rsEmails = CreateObject("ADODB.Recordset")
Set objMessage = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objConfig.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aaaa.org" 
objConfig.Fields.Update
db.Open "Driver={SQL Server};Server=abcd;Database=affu;Uid=A423;Pwd=bs1  900"
rsEmails.Open "SELECT FromEmail,ToEmail, SubjectLine, SentOn, EmailBOdy  FROM EmailData WHERE (Cancelled IS NULL OR Cancelled=0) AND (SentOn IS NULL) AND (DATEDIFF(hh, ScheduledOn, GETDATE()) > 5) ;", db, 3, 3
Set objMessage.Configuration = objConfig 
totalrecords=rsEmails.RecordCount
wscript.echo "Total Records=" & totalrecords
recno=1
prevemail=""
errorcnt=0
on error resume next
while not rsEmails.EOF and (errorcnt < 10)
	if prevemail=rsEmails("ToEmail") then
		errorcnt=errorcnt+1
		wscript.echo rsEmails("toemail") & " ERROR!!!!"
	else
		objMessage.To		= rsEmails("ToEmail")
		objMessage.From		= rsEmails("FromEmail")
		objMessage.Subject	= rsEmails("SubjectLine")
		objMessage.TextBody 	= rsEmails("EmailBody")
		objMessage.Send
		if err.number > 0 then
			errmsg=err.Description
			
			wscript.echo rsEmails("Recipient") & " " & errmsg
			if len(errmsg) > 90 then 
				errmsg=left(errmsg,90)
			end if
			rsEmails("ErrorMessage")=errmsg
			err.Clear
		else 	
			wscript.echo rsEmails("toemail") & " " & formatPercent(recno/totalrecords,0,true,true,true)
			recno=recno+1
			rsEmails("SentOn")=now()
		end if
		rsEmails.Update
		prevemail=rsEmails("ToEmail")
		errorcnt=0
	end if
	rsEmails.MoveNext
wend
rsEmails.Close
db.Close
set rsEmails		= nothing
set objMessage		= nothing
set objConfig		= nothing
set db			= nothing


Thanks in advance

Affu2000

Reply With Quote
  #2  
Old September 30th, 2005, 02:07 PM
affu2000 affu2000 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 13 affu2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 25 sec
Reputation Power: 0
Thumbs up

I figured it out: Replaced the WScript.Echo calls with calls to the WriteLine method of the TextStream object.

Code:
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("EmailLog.txt", ForAppending)
objFile.WriteLine Now
objFile.WriteLine "Total Records=" & totalrecords
objFile.Close


Also, I was reffered to this help page by another user :
http://msdn.microsoft.com/library/en-us/script56/html/FSOoriFileSystemObject.asp

Affu2000

Quote:
Originally Posted by affu2000
The following script is run to send emails to candidates applying for a position.

I want to log any kind of errors that take place during this process and save them in a separate file (like a .log or .dat)

Please help me.

Code:
' VBScript source code
Set db = CreateObject("ADODB.Connection")
set rsEmails = CreateObject("ADODB.Recordset")
Set objMessage = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objConfig.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aaaa.org" 
objConfig.Fields.Update
db.Open "Driver={SQL Server};Server=abcd;Database=affu;Uid=A423;Pwd=bs1  900"
rsEmails.Open "SELECT FromEmail,ToEmail, SubjectLine, SentOn, EmailBOdy  FROM EmailData WHERE (Cancelled IS NULL OR Cancelled=0) AND (SentOn IS NULL) AND (DATEDIFF(hh, ScheduledOn, GETDATE()) > 5) ;", db, 3, 3
Set objMessage.Configuration = objConfig 
totalrecords=rsEmails.RecordCount
wscript.echo "Total Records=" & totalrecords
recno=1
prevemail=""
errorcnt=0
on error resume next
while not rsEmails.EOF and (errorcnt < 10)
	if prevemail=rsEmails("ToEmail") then
		errorcnt=errorcnt+1
		wscript.echo rsEmails("toemail") & " ERROR!!!!"
	else
		objMessage.To		= rsEmails("ToEmail")
		objMessage.From		= rsEmails("FromEmail")
		objMessage.Subject	= rsEmails("SubjectLine")
		objMessage.TextBody 	= rsEmails("EmailBody")
		objMessage.Send
		if err.number > 0 then
			errmsg=err.Description
			
			wscript.echo rsEmails("Recipient") & " " & errmsg
			if len(errmsg) > 90 then 
				errmsg=left(errmsg,90)
			end if
			rsEmails("ErrorMessage")=errmsg
			err.Clear
		else 	
			wscript.echo rsEmails("toemail") & " " & formatPercent(recno/totalrecords,0,true,true,true)
			recno=recno+1
			rsEmails("SentOn")=now()
		end if
		rsEmails.Update
		prevemail=rsEmails("ToEmail")
		errorcnt=0
	end if
	rsEmails.MoveNext
wend
rsEmails.Close
db.Close
set rsEmails		= nothing
set objMessage		= nothing
set objConfig		= nothing
set db			= nothing


Thanks in advance

Affu2000

Reply With Quote
  #3  
Old September 30th, 2005, 05:41 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Thanks for posting your solution.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Urgent: Error Log


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT