July 10, 2008 at 11:21 pm
Comments posted to this topic are about the item VBscript hacks for DTS packages
July 11, 2008 at 12:49 am
Hello!
Still working with VBScript in 2008 year?
Something about .NET it could be very, very interesting.
Regards.
July 11, 2008 at 1:26 am
.NET will not work with DTS...
But very good article. I have had similar "problems" in the past but used different strategies:
When executing other packages within a package I usually use the ExecuteProcess task and build the command line with the parameters in VBScript.
Function fn_BuildArgument(astrType, astrArg1, astrArg2, astrArg3) ' As String
Dim lstrSQLServerName ' As String
Dim lstrCommand ' As String
Dim lstrArgument ' As String
lstrSQLServerName = DTSGlobalVariables("gstrSQLServerName")
' If the parameters are supplied through the command line, neither the percent sign nor the equality sign can be used and therefore must be substituted.
astrArg2 = Replace(astrArg2,"=","decodeequals")
astrArg2 = Replace(astrArg2,"%","decodepercent")
astrArg3 = Replace(astrArg3,"=","decodeequals")
astrArg3 = Replace(astrArg3,"%","decodepercent")
lstrCommand = """C:\Program Files\Microsoft SQL Server\80\Tools\Binn\DTSRun.exe"" "
lstrArgument = "/S " & lstrSQLServerName & " "' The server where the package is located
lstrArgument = lstrArgument & " /E /N""The Package Name " & astrType & """"' The Package to be executed
lstrArgument = lstrArgument & " /A gstrArg1:8=""" & astrArg1 & """"' Argument 1
lstrArgument = lstrArgument & " /A gstrArg2:8=""" & astrArg2 & """"' Argument 2
lstrArgument = lstrArgument & " /A gstrArg3:8=""" & astrArg3 & """"' Argument 3
fn_BuildArgument = lstrCommand & lstrArgument
End Function
Of course this only can be used to submit variables to the called package since they are passed by value and not by ref.
The template method is being used a little differently as well.
I created the template and used special strings (that would never appear in code) as place holders.
During run time, a simple Replace(lstrTemplate,'specialstring', gstrVarName) generates the required SQL String.
For both strategies, it is important to note that these were used by system processes that do not get any user input.
Best Regards,
Chris Büttner
July 11, 2008 at 4:18 am
Well done!
I thought the article was very informative..
July 11, 2008 at 7:20 am
This is a good article although it would help folks if the typo "bidding parameters" got fixed to "binding parameters" as that threw me at first.
Given how flexible the XML parser is, and what with CROSS APPLY and CTE queries, what we do is setup parameters in the database in a table dedicated to that purpose. Might not work for everybody...
July 11, 2008 at 8:47 am
First off I will say it was a nice article and offers so good alternatives. However I will point out two things.
First, in part one there is a " missing in your build of the function right in front of Scripting.Dictionary in the line that reads
sCode = sCode & "Set dictionary = CreateObject(" & chr(34)_
& Scripting.Dictionary" & chr(34) & ")" & vbCRLF
For Each sKey in aEntries.Keys()
This is minimal but for those who cannot figure out why this isn't working it should read
sCode = sCode & "Set dictionary = CreateObject(" & chr(34)_
& "Scripting.Dictionary" & chr(34) & ")" & vbCRLF
For Each sKey in aEntries.Keys()
In addition I am not sure I would consider it helpfull to hide the parameters with this method as you really don't save a lot (and even on a large number of variables you have to resolve somehow the errors). Your statement that you can change variables also does not work as you will have to resolve any issues you get.
Second, I completely disagree with part two, at least based on the example, as I think many people just have not figure out how to manage the things the parameter button cannot parse.
I have worked with DTS for a while now and found this limitation a pain and then discovered via code and ultimately directly how to get around.
For you example just insert the standard parameterized code into the ExcuteSQL task like so
SELECT
MAX(SALES_ORG) AS SALES_ORG,
MAX(DISTR_CHANNEL) AS DISTR_CHANNEL,
DATEADD( hh, ?, MIN( START_DT ) ) AS START_DATE,
DATEADD( hh, ?, MIN( START_DT ) ) AS EFFECTIVE_START_DATE,
PRODUCT_NAME AS PLI_PROD_NAME,
MAX( RATE_ZPMC ) AS MAX_PRICE,
VENDR_NAME,
VENDR_LOC,
VENDR_BU,
DATEADD( hh, ?, MAX( END_DT ) ) AS END_DATE,
DATEADD( hh, ?, MAX( END_DT ) ) AS EFFECTIVE_END_DATE
FROM
TMP_PRI_LST
WHERE
ROW_STATUS = 'FOR_IMPORT'
AND ERROR_MSG IS NULL
GROUP BY
PRODUCT_NAME,
VENDR_NAME,
VENDR_LOC,
VENDR_BU
Now of course if you hit the "Parameters" button you get the error message
"An error occurred while parsing the SQL Statement for parameters. Please ..."
but this is only the parsing code for the button that fails.
To get around this you just need open "Disconnected Edit" (right click on any whitespace of the design area or under Package menu). Once open then expand Tasks and pick the correct item with a name similar to "DTSTask_DTSExecuteSQLTask_" it will have the same description as what you just set if you bothered changing it. Anyway, there you will find an entry titled "InputGlobalVariableNames", edit this item and enter your variable input value like so
"fix_utcdatetime"
and since you have multiple values you have to enter it multiple times and in order like so
"fix_utcdatetime";"fix_utcdatetime";"fix_utcdatetime";"fix_utcdatetime"
The ; is the seperator and the variables are replaced in order. So if you had different values you place in orderinal fashion compared to the ? variable in our query. This works in every case, at least every case I ever tried, where you need it and the button wouldn't work.
July 13, 2008 at 7:18 am
I also thought VBScript now, but after going through the article I found very interesting and nice. It is a informative article.
July 14, 2008 at 12:59 am
Hello Antares,
Regarding your suggestion on the second example (disconnected edit for parameter declaration): It would be very interesting, but I cannot seem to get it to work with Oracle. Do you have any information on this? I have tried various parameter declarations and they all throw errors.
With SQL Server Parameters I have had no issues so far, I was always able to use the Parameter Button for them.
Thanks!
Best Regards,
Chris Büttner
July 14, 2008 at 7:11 am
Yeah, just PM the details of how you are doing you oracle pulls and not what objects you use. Also include the message as I found instances where I had to manipulate formats on dates otherwise it still failed. I usually use Data Drive Query Tasks and there is a completely different way of dealing with them.
July 14, 2008 at 11:46 am
Hm, i tried to get the error message from a new package, but it actually ran successfully this time. Both the oracle and the oledb parameter syntax returned the correct results.
When I tried the same this morning with an existing package I got an error that contained somthing like "Invalid Library" or so. But I cannot reproduce this anymore, so I guess I just had a typo somewhere or something missing.
Thanks for your awesome tip!
Best Regards,
Chris Büttner
July 15, 2008 at 11:36 am
igor.bustiuc (7/11/2008)
Hello!Still working with VBScript in 2008 year?
Something about .NET it could be very, very interesting.
Regards.
That's true. But even if it work with DTS, I would have problems to convince DBAs to learn OOP and .NET just to deal with simple scripts. 🙂
Reusing code in DTS is not a simple task too. How I would be able to justify the burden of using OOP if I cannot reuse code easily?
July 15, 2008 at 11:37 am
Thanks Alan! I just updated the article to fix the type and submitted it again.
July 15, 2008 at 11:49 am
Antares686 (7/11/2008)
First off I will say it was a nice article and offers so good alternatives. However I will point out two things.
Thanks for the feedback Antares686!
First, in part one there is a " missing in your build of the function right in front of Scripting.Dictionary in the line that reads
sCode = sCode & "Set dictionary = CreateObject(" & chr(34)_
& Scripting.Dictionary" & chr(34) & ")" & vbCRLF
For Each sKey in aEntries.Keys()
This is minimal but for those who cannot figure out why this isn't working it should read
sCode = sCode & "Set dictionary = CreateObject(" & chr(34)_
& "Scripting.Dictionary" & chr(34) & ")" & vbCRLF
For Each sKey in aEntries.Keys()
Thank you! I fixed that in the article.
In addition I am not sure I would consider it helpfull to hide the parameters with this method as you really don't save a lot (and even on a large number of variables you have to resolve somehow the errors). Your statement that you can change variables also does not work as you will have to resolve any issues you get.
I'm not sure I really understand the point: even if the method hides the parameters, is easily to explain (the package interface) to another person how to use the package with Execute Package Task if he/she will need to use just one parameter. And the developer can always use some sort of debugging to get information about which values were used during package execution.
Second, I completely disagree with part two, at least based on the example, as I think many people just have not figure out how to manage the things the parameter button cannot parse.
...
To get around this you just need open "Disconnected Edit" (right click on any whitespace of the design area or under Package menu). Once open then expand Tasks and pick the correct item with a name similar to "DTSTask_DTSExecuteSQLTask_" it will have the same description as what you just set if you bothered changing it. Anyway, there you will find an entry titled "InputGlobalVariableNames", edit this item and enter your variable input value like so
Using Disconnected Edit like that may work, but it will make the life of a developer without good documentation or project background more difficult to figure out how the previous developer (me) could make a query work in the DTS package or not! That's make unit testing harder too.
But it's a nice tool also to have available when you need to do a quick fix.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply