Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
fredong
Yak Posting Veteran
80 Posts |
Posted - 2009-02-27 : 15:31:59
|
Hi I am using SSIS 2005 Scrip task on VB.NET and I am trying to pass a value to my input variable thru a function but it seemed like is not capturing the value. Whether I use User:: with a prefix or FullPath is not taking it. There is no error and is not capturing the value in the Variables box. I did debug it for a long time and narrow down it to the Dts.VariableDispenser.GetVariables(vars) is not getting value from varValue. Below is my code. Am I missing something? Please advise. Thanks.' Microsoft SQL Server Integration Services Script Task' Write scripts using Microsoft Visual Basic' The ScriptMain class is the entry point of the Script Task.Imports SystemImports System.DataImports System.MathImports Microsoft.SqlServer.Dts.RuntimePublic Class ScriptMain' The execution engine calls this method when the task executes.' To access the object model, use the Dts object. Connections, variables, events,' and logging features are available as static members of the Dts class.' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.' ' To open Code and Text Editor Help, press F1.' To open Object Browser, press Ctrl+Alt+J.Private Sub WriteVariable(ByVal varName As String, ByVal varValue As Object)MsgBox("In wrtie()")MsgBox(varValue)TryDim vars As VariablesDts.VariableDispenser.LockForWrite(varName)Dts.VariableDispenser.GetVariables(vars)MsgBox("after vars")Tryvars(varName).Value = varValueCatch ex As ExceptionMsgBox("in inner catch")MsgBox(E.ToString)Throw exFinallyvars.Unlock()End TryCatch ex As ExceptionMsgBox("in outer catch")MsgBox(E.ToString)Throw exEnd TryEnd SubPublic Sub Main()'' Add your code hereDim strFolder As StringDim strFilename As StringDim strTomorrow As StringDim strNewFullPath As StringDim objMain As New ScriptMain'Dim FullPath As String'do path in scriptstrFolder = Dts.Variables("User::FolderName").Value.ToStringstrFilename = Dts.Variables("User::FileName").Value.ToString()strTomorrow = CStr(Format(Today().AddDays(+1), "yyyyMMdd"))strNewFullPath = strFolder & strFilename.Substring(0, strFilename.IndexOf(".txt")) & "_" & strTomorrow & ".txt"'display new value of path 'MsgBox(strNewFullPath)Dts.Variables("User::FullPath").Value = strNewFullPathMsgBox(Dts.Variables("User::FullPath").Value)objMain.WriteVariable("User::FullPath", strNewFullPath)'WriteVariable("FullPath", )Dts.TaskResult = Dts.Results.SuccessEnd SubEnd Classk |
|
|
|
|
|
|