March 11, 2004 at 3:08 pm
I've started working with INI files and the Dynamic Properties Task and I was wondering if there is a way to get what the value of an INI key is? I've been able to find these properties pertaining to the use of an INI file with the task, but have not found any information concerning the ability to read what the value is from within code (ActiveX Script).
SourceIniFileFileName
SourceIniFileSection
SourceIniFileKey
If you go into "Add/Edit Assignment" dialog, you can see the value in the INI file in the Preview text box of the dialog. Can I get to this same value from within code???
Below is the ActiveX Script code that I currently have…
Function
Dim obj_Assignments
Dim obj_Assignment
Set obj_Assignments = DTSGlobalVariables.Parent.Tasks("DTSTask_DTSDynamicPropertiesTask_1").CustomTask.Assignments
For Each obj_Assignment in obj_Assignments
msgbox obj_Assignment.DestinationPropertyID & vbnewline & _
obj_Assignment.SourceConstantValue & vbnewline & _
obj_Assignment.SourceDataFileFileName & vbnewline & _
obj_Assignment.SourceEnvironmentVariable & vbnewline & _
obj_Assignment.SourceGlobalVariable & vbnewline & _
obj_Assignment.SourceIniFileFileName & vbnewline & _
obj_Assignment.SourceIniFileKey & vbnewline & _
obj_Assignment.SourceIniFileSection & vbnewline & _
obj_Assignment.SourceQueryConnectionID & vbnewline & _
obj_Assignment.SourceQuerySQL & vbnewline & _
obj_Assignment.SourceType
Next
Set obj_Assignment = Nothing
Set obj_Assignments = Nothing
Main = DTSTaskExecResult_Success
End Function
March 12, 2004 at 4:46 am
Within Windows NT4, Windows 2000 in fact even in Windows 95 & 98 (they also exist in dot net but for the life of me can not recall their namespace) there are available system modules which will read/write an INI file:
In VB code would:
Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$) As Long
Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnString$, ByVal NumBytes As Long, ByVal FileName$) As Long
In Use:
Public Function ReadString(ptSectionName As String, ptKeyName _ As String, INI_FileName As String, txtDefault As String) As String
Dim lCharacters as Long
Dim tBuffer(256)
tBuffer = String$(256, 0)
lCharacters = GetPrivateProfileString(ptSectionName, ptKeyName, "", tBuffer, 255, INI_FileName)
If lCharacters > 0 Then
tIniString = Left$(tBuffer, lCharacters)
Else
'tIniString = ""
tIniString = txtDefault '10/17/02 RMJc
End If
ReadString = tIniString
End Function
Hope this Helps
March 12, 2004 at 7:29 am
So, are you saying that there is NOT a method to get at this value from within the DTS object model? And the only way that I can read the value is from a Windows API call?
Regardless of the answer to the above question, thanks for the code
March 12, 2004 at 9:18 am
You can declare a global variable, assign values from the ini file to the global variable and then read the global variable from the ActiveX script. Would that be acceptable?
March 12, 2004 at 9:32 am
How are you going about reading the ini file value? Are you using the API call or do you know of a way to get to the value through the dynamic properties task object (in code)?
March 12, 2004 at 11:38 am
I use INI file as my main communication method back to calling Package when I have nested packages. DTS is good in forward communication but really bad in reporting results.
I had to build a VB DTSSupport DDL containing FSO APIs etc inorder to easily provide this support. The called packages writes values to INI file then the calling package reads the values into DTS Global Variables. INI values are also read in at start to load any values from previous runs (allows restart capability) and changes to package or file names. The Dynamic tasks then use the Global Variable values to apply changes as needed.
I never could get Dynamic tasks to handle INI files directly. If you want it I am willing to provide the source code for DTSSupport.
SmithDM
March 12, 2004 at 12:33 pm
Hi,
I use Dynamic Property task in every DTS package and find it very easy when you have .ini file:
Sample:
1. Create .ini file
[main]
gsMailTo=jpoddoubsky@dentalxchange.com
gsLoadTo=servername.databasename
[input_files]
gsIncomingFile=D:\reports\abc.xls
gsOutgoingFolder=D:\reports_done
2. Create global variables
gsMailTo, gsLoadTo, gsIncomingFile, gsOutgoingFolder, etc...
3. Open DynamicProperty task properties, click Add, expand GlobalVariables, click on the variable you need to map to .ini file, click Set, source = INI, file = your .ini file, section = main or input_files in our case, key = your gloval variable name, you'll see the value populated from .ini file in Preview pane (sometimes it requires clicking on Refresh).
Keep doing that for every variable you'd like to be set at runtime from .ini file, to keep the window open until you are done - check "Leave this dialog box open..." checkbox in left lower corner.
That's it!
Julia
March 12, 2004 at 1:03 pm
Julia
Ok, That might work in some cases. I would have to test the retrieve portion also to be sure.
However I am getting a little more complex in my routine and find it easier to pass GVar object to VB and just tell routine to write required INI section. On retrieval I just loop through proper Gvar section and retrieve same named INI value. This method allows addition of GVars without modification of associated write/retrieve code.
SmithDM
March 14, 2004 at 4:28 pm
For info on how to pass info back to the calling package, take a look at this article on techniques used in SQL Server BI Accelerator. Pay special attention to the section titled "Information Flow Between Child Packages and Parent Packages"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_dts_ssabi.asp
--------------------
Colt 45 - the original point and click interface
March 14, 2004 at 8:41 pm
Thanks Phill
I will take a look at the metods used for future reference. You can never learn to much. The more you know the more you realize you do not know.
I created my methodogy back in 2000 and it has served me well for major conversions and Data Warehouse processing. (*.INI for comm back from child to parent DTS, RunControl table for SQL Stored Procedure to Comm back to calling DTS Package, SQL proc invoked via OSQL to allow for SQL Log file and return control etc).
By next year with Yukon (SQL 2005) this question will most likely be moot. I understand there are major changes to address DTS's current shortcomings.
Thanks again, Doug
SmithDM
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply