Passing Script variable to Package variable, ultimately used as fileName
Following an excellent post by Geplaatst door Joost, I put together a script which SHOULD populate a package variable, then use that variable as a file name.
The Script code is as follows:
public class ScriptMain : UserComponent
string iScriptVar;
public override void PreExecute()
base.PreExecute();
public override void PostExecute()
base.PostExecute();
Variables.ExtractName = iScriptVar.ToString();
public override void Input0_ProcessInputRow(Input0Buffer Row)
if (!Row.CUSIP_IsNull)
iScriptVar = Row.CUSIP.ToString();
A Windows message box (put in as debug, but removed for brevity here) shows the correct value is being set to iScriptVar at all points it was inserted.
The "ExtractName" variable is checked as a ReadWriteVariables for the Script properties.
But, the "ExtractName" package variable is not being passed to the Expressions for the FlatFile Connection properties, which is set to: @[User::ExtractName].
Where have I gone wrong?
Why not to provide the link to the post already?
iScriptVar
is a local to script variable this explains why it did not you need the full wiring
e.g.
Dts.Variables["User::iScriptVar"].Value = iScriptVar
Arthur
MyBlog
Twitter
Similar Messages
-
Script out SSIS packages from SSISDB using powershell
Hi,
I was able to script out the packages that are on msdb but I was unable to script out that are in Integration services catalog. Does anyone has any idea on how to do this???? Is this possible at all???
Thanks in advance....Can you send me the link in English??
This is how you can get a single package from IS catalog
http://social.technet.microsoft.com/wiki/contents/articles/25913.import-a-ssis-project-from-catalog-using-t-sql-script.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Situation:
SSIS Package designed in SQL Server 2012 - SQL Server Data Tools
Windows 7 - 64 bit.
The package (32 bit) extracts data from a SQL Server db to an Excel Output file, via an OLE DB connection.
It uses 3 package variables:
*) SQLCommand (String) to specify the SQL Statement to be executed by the package
Property path: \Package.Variables[User::ExcelOutputFile].Properties[Value]
Value: f:\Output Data.xls
*) EXCELOutputFIle (String) to specify path and filename of the Excel output file
Property path: \Package.Variables[User::SQLCommand].Properties[Value]
Value: select * from CartOrder
*) VarObjectDataSet (Object) to hold the data returned by SQL Server)
Property path: \Package.Variables[User::VarObjectDataSet].Properties[Value]
Value: System.Object
It consists out of 2 components:
*) Execute SQL Task: executes the SQL Statement passed on via a package variable. The resultng rows are stored in the package variable VarObjectDataSet
*) Script Task: creates the physical output file and iterates VarObjectDataSet to populate the Excel file.
Outcome and issue:The package runs perfectly fine both in SQL Server Data Tools itself and in DTEXECUI.
However, whenever I run it via SQL Server Agent (with 32 bit runtime option set), it returns the errror message below.
This package contains 3 package variables but the error stating that a package variable can not be set, pops up for the VarObjectDataSet only. This makes me wonder if it is uberhaupt possible to set the value of a package variable
of type Object.
Can anybody help me on this please ?
Message
Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility Version 11.0.2100.60 for 32-bit Copyright (C) Microsoft Corporation. All rights reserved. Started: 6:40:20 PM DTExec: Could
not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object. Started: 6:40:20 PM Finished: 6:40:21 PM Elapsed: 0.281 seconds. The package execution failed. The step failed.
Thank you very much in advance
JurgenHi Visakh,
thank you for your reply.
So, judging by your reply, not all package variables used inside a package need to be set a value for when run in DTEXEC ?
I already tried that but my package ended up in error (something to do with "... invocation ...." and that error is anything but clearly documented. Judging by the error message itself, it looks like it could be just about anything. that is why I asked my
first question about the object type package variable.
Now, I will remove it from the 'set values' list and try another go cracking the unclear error-message " ... invocation ...". Does an error message about " ... invocation ..." ring any bells, now that we are talking about it here ?
Thx in advance
Jurgen
Yes exactly
You need to set values only forthem which needs to be controlled from outside the package
Any variable which gets its value through expression set inside package or through a query inside execute sql task/script task can be ignored from DTExec
Ok I've seen the invocation error mostly inside script task. This may be because some error inside script written in script task. If it appeared after you removed the variable then it may because some reference of variable existing within script task.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Package variables vs procedure arguments
Is it better to use package-level variables inside package or to use procedure arguments?
I'm just asking because I have a bunch of parameters for each procedure (all of them are private, and are only called from within the package).
Is better this:
package a
is
--package variable
v_something my_table%rowtype;
procedure a
is
--do something with v_something
end;
procedure b
is
select * into v_something
from my_table
where rownum=1;
--call it without parameters
a;
end;
end;
or this:
package a
is
procedure a(inSomething my_table%rowtype)
is
--do something with v_something
end;
procedure b
v_something my_table%rowtype;
is
select * into v_something
from my_table
where rownum=1;
--call it with parameters
a(v_something);
end;
end;Please post between the tags
..... and {code }
If you have multiple procedures updating and reusing the package variable you loose track of what value you have in the package variable.
And it depends what you are trying to do. -
Trouble passing variable into package
I am having an issue reading a variable in a script task that I'm passing in from a windows service. I should be able to pass the param in from .NET and load it into one of my package vars right? The windows service is a file watcher service.
Windows Service code
Package pkg;
Application app;
DTSExecResult pkgResults;
Variables vars;
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);d because I log it to a log file.
vars = pkg.Variables;
vars["User::FileName"].Value = sFileName.ToString();
pkgResults = pkg.Execute(null, vars, null, null, null);
The sFileName variable in the service is populated because I write it to a log file.
In the package I list the FileName variable as read/write. Have checked the spelling.
package code snippet:
public void Main()
//get file and path info
string sFileName = Dts.Variables["User::FileName"].Value.ToString();
the package fires but the variable is empty and I log an exception to the sysssislog:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) at ST_5a4733488a6149abb109d633296e2c38.csproj.ScriptMain.Main() --- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object
target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
I cannot find what the issue is. In the package I log to a text file the value of FileName variable and as expected it is empty.
I appreciate your help witThe scripting task which is designed to retrieve the file name from the package var User::FileName is listed in the scripting tasks read/write variables and it is a package level variable. Is that what you mean by "expects" Arthur? If so then yes. But is
there a property setting on the script task that has to be set?
I could use the config file but the file name changes daily with a date stamp suffix. I could also just sweep the directory when the file watcher executes the package but that all seems so sloppy considering that I should be able to pass the filename in
as a variable.
Thanks for talking through this with me. I appreciate it. -
Using global variable in package
Hi. I have created a function (Retrieve_SerialNo) which returns a variable, which I use throughout my package. I would like to assign this variable as a global variable to be used by all functions and procedures in the package. Can someone help me in the declaration of this variable as a global variable? Also, is it necessary for me to initialize this variable whenever the package executes. If yes, how would I do this?
CREATE OR REPLACE PACKAGE BODY Supply_Item_Interface AS
FUNCTION Retrieve_SerialNo RETURN VARCHAR2 IS
v_serial_no VARCHAR2(20);
CURSOR Serial_Code IS
SELECT S.Serial_Code
FROM Spare_Parts s, Orders r
WHERE s.serial_code = r.serial_code;
BEGIN
OPEN Serial_Code;
LOOP
FETCH Serial_Code
INTO v_serial_no;
EXIT WHEN Serial_Code%NOTFOUND;
v_serial_no := v_serial_no;
END LOOP;
CLOSE Serial_Code;
RETURN v_serial_no;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END;user13415143 wrote:
Hi. I have created a function (Retrieve_SerialNo) which returns a variable, which I use throughout my package. I would like to assign this variable as a global variable to be used by all functions and procedures in the package.All variables have scope or "visibility". A variable defined in a procedure is only visible within that procedure.
A variable defines in a package body. is visible within that package body (i.e. procedures and functions in that package body can "see" that variable.
A variable defined in the package definition? Well, who can see the definitions of procedures and function in a a package header/definition? Everyone else basically (other PL/SQL packages and procedures and functions). So this is also true for variables defined in the package interface. These are global variables that not only can be used by the code in that package's body, but also can be used by other packages and PL/SQL code.
So when you create a global variable you need to decide on its scope:
- define it in package header for global usage in all PL/SQL code
- define it in package body for global usage within that package only
CREATE OR REPLACE PACKAGE BODY Supply_Item_Interface AS
..snipped..Ugly code as there is no need to use an explicit cursor if returning a value from a single row. Also buggy code. If there are multiple rows returned by the cursor, the function returns the serial of the last random row. How does this make sense?
This is what I would expect to see from a function like this. You pass it a unique identifier and it returns the applicable attribute (column) value for it.
E.g.
create or replace function GetSerialNo( orderNo number ) return number is
serialNo number;
begin
select
s.serial_code into serialNo
from spare_parts s,
orders o
where s.serial_code = o.serial_code
and o.order_no = orderNo;
return( serialNo );
exception when NO_DATA_FOUND then
return( null )
end;Also note that there is no need to write ugly uppercase code. This is not a proper coding standard. Programming standards for all languages (ranging from C# to Java to Delphi to Visual Basic to C/C++) specify that camelcase should be used for variables and pascalcase for procedures/functions/methods. Uppercase is very seldom used and then only for constant names and compiler options/flags for example.
Coding reserved words in uppercase? That is just plain silly - and not found in today's programming languages. Do yourself a favour and forget the idiotic standards used by some for PL/SQL and look at the standards for Java and .Net/C# - as the latter are the de facto standards for programming (and have been for the last 2 decades and more). -
Pass value of Java script variable to ABAP variable (in BSP)
Hi,
I have a Javascript variable declared in the SCRIPT tag of BSP layout page.
I want to pass its value to ABAP variable, so that later I can do some computations using the ABAP variable.
(ABAP variable is also declared in the same SCRIPT tag of BSP page)
Would request to post a sample code, if possible.
Would appreciate quick replies.
Thanks & Regards,
Nisha Vengal.just check this
https://forums.sdn.sap.com/click.jspa?searchID=16240444&messageID=1191305 -
Passing Record Variable through Packages
I have a question and hope that someone can help me to find the solution.
I'm developing an application and I need to pass values form one procedure PR in package B to a function FN in package A. The why I try to go is passing the values by using a variable of record type.
I have defined in both packages the same record structure that I also use in the declarations of procedure and function. I first compiled successfully the package A but when I try to compile the package B I get a compilation error:
PLS-00306: wrong number or types of arguments in call to 'B.FN'
It looks like the parameter definition or reference gets lost.
Here below a very schematic example of my application:
create or replace package A is
type Rec1 is record
( rf1 T.f1%type,
rf2 T.f2%type,
rf3 T.f3%type)
function FN ( Par in Rec1 ) return boolean;
end;
create or replace package A is
function FN ( Par in Rec1 ) return boolean is
V_ret boolean;
begin
whatever it does
return V_ret ;
end;
end;
create or replace package B is
type Rec1 is record
( rf1 T.f1%type,
rf2 T.f2%type,
rf3 T.f3%type)
procedure PR ( Par in Rec1 ) return boolean;
end;
create or replace package B is
procedure PR ( Par in Rec1 ) is
VP Rec1;
V_go boolean;
begin
VP.rf1:= something_1;
VP.rf2:= something;
VP.rf3:= something;
V_go:=FN ( VP ); <= here the compiler complaints
whatever it does
end;
end;
Many thanks for a quick answer.Okay I didn't notice the error message text in the body of the paragraph above.
PS. If I specify singularly the fields in the parameter list I pass the compilation
but I would like to use a record variable as one.Did you see my post where I always reference the record variable in package A?
create or replace package B is
procedure PR ( Par in A.Rec1 ) return boolean;
end;
create or replace package B is
procedure PR ( Par in A.Rec1 ) is
VP A.Rec1;
V_go boolean;
begin
VP.rf1:= something_1;
VP.rf2:= something;
VP.rf3:= something;
V_go:=A.FN ( VP ); <= here the compiler complaintsIt should work. -
How do I use bin variable in package without asking a user?
hi,
I would like to write an SQL but I want to use bind variable in package as a static without asking user? Like below?
I would like to ask you, below there is a emp_id variable? Is this BIND variable?
DECLARE
bonus NUMBER(8,2);
emp_id NUMBER(6) := 100;
BEGIN
SELECT salary * 0.10 INTO bonus FROM employees
WHERE employee_id = emp_id;
END;
If not, like this SQL how can define a BIND variable as static inside a code? not asking a user?
db version. 9.2.0.8
regards and thanksOracleADay wrote:
I would like to ask you, below there is a emp_id variable? Is this BIND variable?
DECLARE
bonus NUMBER(8,2);
emp_id NUMBER(6) := 100;
BEGIN
SELECT salary * 0.10 INTO bonus FROM employees
WHERE employee_id = emp_id;
END;
/In the query "SELECT salary * 0.10 INTO bonus FROM employees WHERE employee_id = emp_id" emp_id is turned into a bind variable because
if you are coding static SQL in PL/SQL then PL/SQL wil automatically use bind variables: please read http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/overview.htm#sthref145.
This can also be proved with SQL trace. The following code:
alter session set sql_trace=true;
declare
v number;
c number;
begin
select count(*) into c
from t
where x=v;
end;
show errors
alter session set sql_trace=false;generates following raw trace file section with 10G XE:
=====================
PARSING IN CURSOR #2 len=79 dep=0 uid=69 oct=47 lid=69 tim=33338762257 hv=2860574766 ad='3c10120c'
declare
v number;
c number;
begin
select count(*) into c
from t
where x=v;
end;
END OF STMT
PARSE #2:c=46800,e=329811,p=0,cr=9,cu=0,mis=1,r=0,dep=0,og=1,tim=33338762253
=====================
PARSING IN CURSOR #1 len=35 dep=1 uid=69 oct=3 lid=69 tim=33338788761 hv=3539261652 ad='3c10053c'
SELECT COUNT(*) FROM T WHERE X=:B1
END OF STMT
PARSE #1:c=0,e=216,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=1,tim=33338788755
=====================Edited by: P. Forstmann on 17 mai 2011 17:47
Edited by: P. Forstmann on 17 mai 2011 17:55 -
Using Oracle package variables in JDBC.
Can anybody know how we can use Oracle Package variable in Java/JDBC?
I am using a insert trigger on a table which will initialize the login user
from a package variable.In my log4j configuration file, while inserting data into this table, I am updating the user with my current user. But the insert statement is not identifying the user and it is inserting null.
PLease let me know.Siva,
You said:
It is not inserting the user in the tableI see no table, here. Only a variable in a PL/SQL package.
You also said:
But the same is working in Oracle.Do you mean in SQL*Plus?
Siva, try to forget how you are doing it, and tell me what you are trying to do.
Do you have some UPDATE_USER column in your database tables where you record the username of the person who did the operation?
Are you trying to write a trigger that populates this column?
If so, then all you need is something like:
create or replace trigger MY_TRIG
after insert or update
on MY_TABLE
for each row
begin
:new.UPDATE_USER := user;
end;Good Luck,
Avi.
P.S. By the way, what has this to do with OC4J? -
Forms 10 and PL/SQL: Using a server package variable
Hi,
I have a variable created at package level in the server,
When I try to assign its value to a Forms item, I get an error.
"Unable to access distant package variable".
What should I do to access this variable?
Many thanksHello,
Add to the package a procedure to set this variable, and also a function that returns the variable content.
Francois -
Package Variable Values in For Each Contaner
I have a For Each File Container that loops through Excel files, executing a child package for each file found. I am using the RowCount transform to log the number of rows at various points in a DataFlow. When one file is processed the numbers are correct
but when multiple files (e.g. 5) are processed some counts are zero when they shouldn't be. I have tried a 1 second sleep in the loop but that didn't fix the problem.
R CampbellPlease share more technical details
numbers of what where, what Data Flaw how a package reports on the counts?
Arthur
MyBlog
Twitter
Actually, the title IS misleading.
I have a parent package with a For Each File container
and within that a child package is called, passing the file path and name. The child package has a
DataFlow with quite a few branches in the flow. On some of those branches I have
RowCount "transforms" each linked to its own
package variable.
At the CotrolFlow level a script is executed immediately after the DataFlow which writes the package variable values to the dts log.
If I place one file at a time into the folder that the For Each Container is looking at and wait for it to be processed, the numbers are correct. If I place a number of files (say 5) in the folder at one time, some of the numbers logged are correct
and some are zero.
I did try a 1 second sleep at the start of the logging script but, when I think about it, the package variables probably being read before the script starts to execute. If this is a timing issue (which I don't think that it should be) it might need
to be a separate script between the DataFlow and the existing script, with a sleep in it.
Because each loop of the parent package executes a new instance of the child package I am puzzled as to how there can be a timing issue. No matter how tight the loop might be, a new instance of the child package is executed each time.
R Campbell -
Hi,
VS2008
SQL 2008 R2
Bit of a newbie with SSIS and script tasks. I have a simple package that defines two package variables.
I'm trying to read these in the Main() method of the C# script task.
However this gives the following error.
System.Runtime.InteropServices.COMException (0xC0010009): The element cannot be found in a collection.
This would imply that the variable does not exist in the variables collection, however it does. I've tried both Package:: and User::, same result.
Googling this seems to show that square brackets are correct for C#.
Any ideas?Why are you assigning a single string value to object variable? you should be assigning it to a string variable.
Trial and error really. I started with String and when it didn't work I changed to object.
Did you pass the variable in Script Task properties? If you want to read the value alone include it within ReadOnly variables. If you want to modify value make it ReadWrite
If not you wont be able to use it in script body and will get element not found error.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Using a variable inside another variable
I'm trying to use one two variable in a package with one variable feeding its value to another variable as follows:
Variable 1 = Count
Variable 2 = File_Name
Variable 1 counts up from 1;I would like to use this value as an input to Variable 2 as follows:
SELECT LOAD_FILENAME FROM DIMSTATS_FILENAME WHERE (SELECT ROW_NUMBER() OVER (Order by FILE_ID) AS RN FROM DIMSTATS_FILENAME) = #DIMSTATS_TEST.count.
How ever I am getting the following Error :
+ODI-1228: Task File_Name (Variable) fails on the target connection DDBSTAGE.
Caused By: java.sql.SQLException: [FMWGEN][SQLServer JDBC Driver][SQLServer]The multi-part identifier "#DIMSTATS_TEST.count" could not be bound.+
I have also noticed that the value of Variable 1 is not being passed to the Select statement above through SQLServer Profiler. If I hard-code the value of #DIMSTATS_TEST.count (Variable1) the query is successful.
How can I get the value of Variable 1 to be passed to Variable 2?
Could someone please help
ThanksYou did not mentioned how you are using those variable .
You need to have these variable inside a package .
It will be like
Variable 1 (Refresh) -------OK-------->Variable 2(Refresh) ------------OK-----> Some other operation .
Thanks,
Sutirtha -
Passing JavaScript values to JSP variables
Can any body correct the follwing code
<Script language="JavaScript">
function test( x )
<%
int num = x;
num = num * 2;
%>
v.value = "<%out.print(num);%>";
<input type="button" name="b" value="test" onClick="test(5)">
<input type="text" name="v" value="0">
In short, I am trying to pass JavaScript value to JSP variable. I hope that it is possible to do that. If it is possible then how can I do it. I want to assing the variable x passed to the JavaScript function called test to the JSP variable called num.
Regards,
AgeelThank you for your reply,,,
I think then the only way to do it is to post the
value on the server and then use request.getParameter
method in jsp code
but the question now how can I post values to the
server using JavaScript without reloading the pageyes... you can to it by create a new popup window which will submit the value to server after page was loaded... then, server return a value to the same window in html/jsp page which then using javascript to set it back to the opener and close up the window... however, this is not a good choice unless you have no other alternative...
>
There is other possible solution
if I can get the text field value from the same page
without reloading it that would work fine and will
solve my problem, is it possible?yes... you can get the value from the textfield...
for example :
function showValueInTextField()
alert(document.forms[0].elements["mytextfieldname"].value);
>
My final question> can jsp change things on the same
page without reloading it. I mean can it work like
JavaScript so that I can use it's internal functions
instead of using java script :S
not really know what you trying to say here...
Maybe you are looking for
-
PSE10 Oraganizer slide show Pixelate 3D problem
I'm having a strange problem with the 3D Pixelate transition in windows Organizer slideshow. It zooms in on the picture and crops it severely whenever it runs. The other transitions work fine. Any ideas? I'm running Windows 7 on a new computer. T
-
Remediation problems in Captiveate version 6.1.0.319
The remediation does not work in the project I am workin on. Failure level: 1 Last attempt: Jump to slide Slide: 8 slide 8 If I answer the question correctly it works fine. If answered incorrectly I get the "incorrect: click anywhere.." and when
-
I have been trying out a WRT1900AC router for about a week and just developed a MAJOR drop in speed from the router to the computer while doing a file transfer: This thing has been sending files to and from the router's esata and USB3 port at over 5
-
Question about exporting albums
All my photos are on an external hard drive. Is there a way to also export album info so that if I import those photos into iphoto on another computer I can import the album info too? I want to do what you can do in iTunes (exporting playlists). Is t
-
Don't know how to sync my iPod and my sisters iPhone to the same computer.
We use separate iTunes accounts. I reformatted my computer and need to sync both. My iPod says it will delete all my apps and replace it with hers if I do. Anybody know how to do this?