DynDeveloper.com

DynDeveloper.com

Sign Up Now! Log In
JAGuyton 3/19/2013 3:58:57 PM

VBScript Error Primary Message: Cannot write to a closed TextWriter

Hello

I am trying to write a post integration script to email an error log file after an integration has completed using SQL mail.  I know that my SQL mail script works and sends the file that I designate.  I know that the script will find the correct file; but, the error log changes names each time I run the Integration, which means I have to pass a VBScript Variable to a SQL stored procedure.  Here is my code:

 

'****************GET THE LOG FILE INFO******

'*******************************************

 'Set the path to the log files. Edit this line as appropriate

sLogPath="D:\DYNSHARE\Log\"

 Set sFileName = CreateObject("ADODB.Parameter")

 Set pFSO = CreateObject("Scripting.FileSystemObject")

Set pFolder = pFSO.Get Folder(sLogPath)

 dtDateCreated=CDate("1/1/1900")

 For Each File In pFolder.Files

 If File.DateCreated > dtDateCreated then

 dtDateCreated = File.DateCreated

 sFileName=File.Name

 End If

Next

MsgBox (sFileName)

'*******************************************

'************CREATE AND SEND THE E-MAIL*****

 '*******************************************

Set pConnection = CreateObject("ADODB.Connection")

Set xFileName = CreateObject("ADODB.Parameter")

Set xFileName=sFileName

 'Open the connection to the database

 Call pConnection.Open("msdb","sa","Cashmere_3")

'Execute the stored procedure Call

 Call pConnection.Execute("DECLARE @filename varchar(8000) exec INSCIO_SendInegrationLog set @filename=xFileName")

 'Close the connection

Call pConnection.Close

My Error is occurring on the bottom half of the code when it is trying to pass the variable value I created xFileName to the SQL stored procedure.  Here is the exact error I am getting:

Integration Manager Exception Detail Log
Date: 3/19/2013 3:01:00 PM

Message Values:
 Primary Message: Cannot write to a closed TextWriter.
 Exception Message: Cannot write to a closed TextWriter.

Stack Informaiton:
 Source: mscorlib
 System.IO.__Error.WriterClosed()
 System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
 System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
 System.IO.TextWriter.WriteLine(String value)
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.LogManager.AddActivity(Log Log, DateTime ActivityTime, String Source, String LogText, Int32 StatusCode)
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.Log.AddActivity(DateTime ActivityTime, String Source, String LogText, Int32 StatusCode)
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.IntegrationContext.WriteLogActivityEntry(String Source, String LogText, LogClassEnum LogClass, Int32 StatusCode)
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.IntegrationContext.IIntegrationEngine_Run()
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.IntegrationContext.Microsoft.Dynamics.GP.IntegrationManager.IMProvider.IIntegrationEngine.Run()
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.Integration.IIntegration_RunIntegration(IntegrationContext IntegrationContext)
 Microsoft.Dynamics.GP.IntegrationManager.IMProvider.Integration.Microsoft.Dynamics.GP.IntegrationManager.IMProvider.IIntegration.RunIntegration(IntegrationContext IntegrationContext)
 Microsoft.Dynamics.GP.IntegrationManager.frmProgress.frmProgress_Activated(Object eventSender, EventArgs eventArgs)

Data:

End Log

 

Any ideas what is wrong with my code?

 

Thanks - Joseph Guyton

 

Version: GP 2010
Section: Integration Manager, SQL Scripts, VBA