Search the GP Tables
Search by TABLE NAME
Search by FIELD NAME
These are our SOP scripts. All of our scripts for Dynamics GP can be found here

Table Edits Forum Articles
Table Edits 0 Table Edits 0 Table Edits 0
Sign Up Now!Log In
JAGuyton 3/19/2013 3:58:57 PM

VBScript Error Primary Message: Cannot write to a closed TextWriter


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


 Set sFileName = CreateObject("ADODB.Parameter")

 Set pFSO = CreateObject("Scripting.FileSystemObject")

Set pFolder = pFSO.Get Folder(sLogPath)


 For Each File In pFolder.Files

 If File.DateCreated > dtDateCreated then

 dtDateCreated = File.DateCreated


 End If


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.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.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)


End Log


Any ideas what is wrong with my code?


Thanks - Joseph Guyton


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

Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables