Pages

Friday, March 12, 2010

Script task recompilation Error

A package that has a script task runs fine in visual studio, but the package fails as a job with following error on DEV Server.

"Script could not be recompiled or run: Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

OR

Error 1 Validation error. Script Task : The task is configured to pre-compile the script, but binary code is not found. Please visit the IDE in Script Task Editor by clicking Design Script button to cause binary code to be generated.”

Answer:

  • Check the pre-complied property of script task.
  • Change it to TRUE
  • Add the following code in your script, before imports statement.

                    Option Strict Off
                    Option Explicit On
                    Imports System
                    .
                    . 



Tuesday, March 9, 2010

Checking for the file?


Question:
Many times I observed on MSDN SSIS forum that developers are facing problem for checking the file in a particular folder. There are 2 types of checking:

1> Is any file exist in the folder?
OR
Count number of files in a directory through SSIS

2> A particular file is exist [for example c:\Manish\demo.txt]

Answer:

1> Is any file exist in the folder? OR Count number of files in a directory through SSIS?


For checking the file existence in a directory, there are 2 ways

1: File Property task
File Properties Task .  It will detect file existence. Check the link.

2: Script task

Step1: Take a ForEachLoop container.
Step2: Map to the particular directory.

Step3: Inside that you have to use a script task and there you can write following code to count the no of files.

Step4: Define the following variable @ package level 
 
User::Count

 
---------------------------
|   ForEachLoop             |
---------------------------
|
|            --------------
|            |Script Task |
|            --------------
|
---------------------------

Step5:

Public Sub Main()
    Dts.Variables("User::Count").Value = Dts.Variables("User::Count").Value + 1
    MsgBox(Dts.Variables("User::Count").Value.ToString())
    Dts.TaskResult = ScriptResults.Success
End Sub
    
Now you can access the count variable



2> A particular file is exist [for example c:\Manish\demo.txt]

You can use a script task to check if the file exists or not. Suppose I have demo.txt in C:\Manish then I will use a script task with code as:
 
Public Class ScriptMain
    Dim flag As Boolean
    Public Sub Main()
        flag = File.Exists("C:\MyFolder\demo.txt")
        If flag = True Then
            System.Windows.Forms.MessageBox.Show("File Exists")
        End If
    Dts.TaskResult = Dts.Results.Success
    End Sub
End Clas



Hope this will help you. Give your suggestion to improve this post.