Showing posts with label package. Show all posts
Showing posts with label package. Show all posts

Thursday, March 22, 2012

Custom Task: How to access/modify the variables of a package

Hi,

I'm trying to simplify the deployment process of my project. I already had some troubles with the config files but lets say I solved that issue. I'm going to read a flat file and set the variables of my packages from this file. I was thinking to use a Script Task to do that but I will need to copy this task in every package (I have at least 30). So if I want to make some change this will be painful.

Then, I came up with the idea of creating a Custom Task called Config File Task. I'm working on this but I got stuck trying to get the variables from the package that is running my Config File Task.

This is the code I had in the Script Task:

Dim streamReader As New StreamReader(Dts.Variables("ConfigFilePath").Value.ToString)
Dim line As String
Dim lineArray As String()
Dim variableName As String
Dim variableValue As String
Dim readConfigurations As Boolean = False

While (streamReader.Peek() <> -1)
line = streamReader.ReadLine()
If line = "[CONFIGURATIONS]" Then
readConfigurations = True
ElseIf line = "[/CONFIGURATIONS]" Then
readConfigurations = False
Else
If readConfigurations And line <> "" Then
lineArray = line.Split("|".ToCharArray())
variableName = lineArray(0).Trim()
variableValue = lineArray(1).Trim()

If Dts.Variables.Contains(variableName) Then
Dts.Variables(variableName).Value = variableValue
End If
End If
End If
End While
Dts.TaskResult = Dts.Results.Success

All I want to do is set the variables that exists in each package from the config file. In my UI Class (ConfigFileTaskUI.cs) I can have access to the variables via the TaskHost which is passed as an argument of Initialize() method.

Any thoughts? I'd really appreciate some help!

P.S. I've been working on this for 2 days!

I don't have an answer to your question, but have you looked at using package configurations (SSIS > Package Configurations from the BIDS menu)? these can be stored as simple XML files that can be used for the same purpose as what I think you are trying to do here.

Note that BIDS will not save connection string passwords for you - you would have to open the XML file and edit it manually to add these if you are using it for connection strings.

You can use these XML files to store variable values as well as lots of other properties of your package objects. You could write your own code to manipulate the contents of the XML configuration files however you like.

Another option would be to store your values in a database and fetch the values into the variables using SSIS Execute SQL tasks or a similar method.

Maybe you've thought of all this already and ruled it out for some other reason - but based on your post this would seem a much simpler method?

|||Hi Slicktop,

Yes, I tried the XML config file but you cannot have configurations that don't exists in the package. About the SSIS_Configuration table, I thought of this but it's not a good idea for my deployment process. Somehow, I need to get the information from this table and put it in a flat file so I can store it in CVS. Plus, I need to fill this table every time I deploy my packages. I know this is not so difficult but my client don't want to do this.

There is a property in the Package object which disable the warning messages from the configuration file. If I set to True, I don't get an error message when I have just one XML config file with multiple configurations which they may or may not exists in the package to be executed. I don't like doing this because it doesn't seem right.

Thanks for your ideas.|||

What about just reading the flat file using SSIS? You could either load it into a work table and then query it to set variables, or maybe even use a transform to extract the values you need.

When you say "you cannot have configurations that don't exist in the package", what do you mean exactly? Your variable names aren't defined in the package?

|||That's right!. I don't have the same variables in every package. I have a log file per package so in the flat file I have:

log_package_1 = something
log_package_2 = something
log_package_3 = something
conn_db = connection string to db
file_vpn = path to the vpn file

and so on, so in package 1 I only have declared variable log_package_1 but not the rest of the variables of my flat file. Reading the flat file with SSIS could be a possible option but the thing is I have a custom flat file, I mean it's not comma separated and I have some "tags" so I don't think SSIS can read it.

Thanks for the ideas!|||

well obviously I don't know all the details of your situation but it sure seems like you are trying to do this the hard way.

Is there some reason why your custom flat file has to have a "custom" format?

If your goal is to dynamically populate package variables, and the variable names are defined in the package definition, then you can use package configurations to do this. If your goal is to have only a single flat file that contains all variable values across multiple packages, then why not just write these into a standard, machinable format (XML, delimited file, whatever) and then use SSIS to load the file into a DB table. Then from each package, query the table for the variable values needed for that particular package and use the resultset to populate the package variables.

Your table could be generic, with two varchar columns, var_name and var_value.

so, in package 1, you could write an execute SQL task that runs "select var_value from control_table where var_name = 'log_package_1', etc.

If you put a bit of thought into this you could probably make parts of this solution quite generic so that you could write it once and copy/paste the tasks into each package or nest your packages to re-use it. for example, maybe add a "package_name" column to the control table that you could use to query all variables for a package using the same SQL.

sorry, I know I haven't answered your original question (don't know the answer) but thought maybe there is a better (easier) way to do this.

|||Why are you punishing yourself with such a masochistic task?

I mean, why not just use XML Configuration files?|||

Has the original question been answered?

The Task.Execute method is where you will place the code that reads from the file and sets variables. The execute gives you access to the VariableDispenser object as on of the parameters, in much the same way as the TaskUI.Initialize method does, is this not enough?

The Dts.Variables syntax you have used in the Script Task is not applicable, you need to manually control the locking in the variable dispenser. Look at the Lock* methods as documented for the variable dispenser.

|||Hi DarrenSQLIS,

No, the original question haven't been answered yet. I know that Dts.Variables is not applicable in my case when creating a Custom Task. I checked the VariableDispenser object and there are a few methods. For example, the GetVariables(ref Variables variables) but I don't have the collections of variables to pass it as the parameter for this method.

I think I need somehow to tell SSIS which variables are for read-only access and which ones are for read/write. Even so, I would like to know first the variable name and their respective values first. The VariableDispenser object seems useless because I don't know how to get the variables within the package that is executing my Custom Task.

My goal is to know the name of all the User Variables in a package and then set these variables to their respective values that I'm reading from a flat file.

Using XML configuration files is not a solution, I'm not going to set the SuppressConfigurationWarnings property to True in each package. Probably you think I'm trying to do it the hard way but I have to follow some constraints and standards from my client.

Thank you all for your replies.|||

The methods, GetVariables, LockOnForRead or LockOneForWrite all expect a reference parameter of type Variables. This is just the variables collection that is filled with the 'locked' variables that you have asked for, e.g.

Variables variables = null;
variableDispenser.LockOneForRead(this.SnapshotName, ref variables);
snapshotName = variables[0].Value as string;
variables.Unlock();

From what you're saying though you don't know in advance what variables you want to lock, and that is a problem. There is no way to just ask for a list of all variables. I assume your pseudo config item and the variable name match, so at best you can loop through the config items and ask if a variable of that name exists, using the VariableDispenser.Contains method. If found then lock it and do what you want, but you cannot just eneumerate a collection of all variables in the package to find out what is there.

|||Hi DarrenSQLIS,

Yeah, you're right! My pseudo config item and the variable name match so I can loop through the config items and that's what I did. I wasn't understanding the purpose of the GetVariables() method of VariablesDispenser. After I played with it some time I realized it copies the variables from the package that you lock (read-only or r/w) before to the Variables collection that you pass by reference. Then you can access the variables from this collection and set them. What I don't understand completely is how the variables are return to the package or VariablesDispenser. I'm guessing is after you unlock them.

Well, thank you so much for your tips/ideas/suggestions. I finally finished building my Custom Task as I wanted. It's a shame you cannot access all the variables without knowing the name of the variables ahead. In this case I'm assuming that whatever is in the package is also in the config file but my process will fail if the package has a variable that the config file doesn't.sql

Custom Task and Reading Package Configuration

Hello All,

I have searched on this forum for a similar question but couldn't find it so I apologize if this has been asked. If so, I'd greatly appreciate a link to the question. I have created a custom task and am trying to read an xml package configuration file within my custom task. To be more specific, I have added an ADO.Net Connection to my database onto the package and have generated the appropriate tags within my package's configuration xml file. I'm not seeing the classes I should use to access the configuration file of the package I've created. Does anybody have any ideas how I can accomplish this or a link to a document that might cover the material? Thanks!

Jay_G

Jay,

First, let's be sure that what you're trying to do is what you really want to do.

Why do you want to read the configuration? Are you trying to do something with the configuration or do you simply want your custom task to be configured?

|||

Hello Kirk,

Thank you for responding. My custom task will, at times, need to read from a database and I figured the standard database connection string parameters would all be within the configuration file. I initially thought that I would need to use a package connection but the original intent of this custom task is be as easy to use and seemless as possible (meaning drop the task on the designer, set a few properties and be done). The custom task will be used over and over again within many packages. We didn't want to make all of our package developers have to configure a connection for this task but maybe this approach doesn't make sense. Does that make sense or should I be doing it a different way? I'm very new to SSIS and very much open to suggestions. Let me know if you need more clarification. Thanks again.

Jay_G

Wednesday, March 7, 2012

Custom Dataflow Transform in Programmatically Built Package

I'm building packages programmatically and all is well. I have a new custom transform that I developed. It also works fine. Now I'm trying to add my new component to my packages when I programmatically build them, and I'm unable to do that.

Has anyone added their own custom components to a programmatically built package successfully?

I get a COM error on the line that calls ProvideComponentProperties. I've attempted various modifications including not overriding ProvideComponentProperties or just having it do nothing. I always get the same result. What I don't understand is that the custom transform works and handles ProvideComponentProperties fine when it is added to a package in BIDS.

Thanks.

'Add new dataflow task

combitronics = dataFlow.ComponentMetaDataCollection.New()

'Set assembly to my component

combitronics.ComponentClassID = "Ewrap.SSIS.Combitronics"

'Get instance of component

Dim instance As CManagedComponentWrapper = combitronics.Instantiate()

'Initialize component ***Error Occurs Here***

instance.ProvideComponentProperties()

...

Have you tried debugging your custom component. The only other thing I could suggest is where the component is deployed to.|||

Thanks for the response.

It looks like I'm using the wrong name for my assembly when calling it. I found I could specify the GUID instead of the Namespace.Name format and that solved the problem. I got the correct GUID by looking at the .dtsx file after renaming it to .xml so it's easily viewed in IE.

Saturday, February 25, 2012

Custom Control Flow Item Issue

I've been using Konesan's FileWatcher control-flow item successfully in design-mode on my PC, which runs the package on a remote server.

I have installed the Konesan's FileWatcher on the remote SQLServer machine. I then imported the package to the server (Files System folder). I then select the package, right-click 'Run Package', then Execute, and receive the error:

"Error: The task 'File Watcher Task' cannot run on this edition of Integration Services. It requires a higher level edition"

..in the 'Package Execution Progeress' dialog. All other validation seem to be ok.

(Note, I'm executing the above steps using SQLServer Mgt Studio from my PC ; I'm not doing it from the SQLServer machine itself...not sure if this matters or not.)

The SSIS version installed on the server is 9.0.3054. It shouldn't be an "SSIS version issue", as it is the same SQLServer that I used (successfully) from my PC in design mode...

Thanks,

Allen

SSIS is not likely installed on the server. Grab the installation media and verify that SSIS is installed. Better yet, look at the services on the server and see if there's a SQL Server Integration Service.|||

When you execute from SQL Server Mgt Studio, actually it runs from your system and not on server. Hence you will need SSIS installed on your box to run it locally.

This should give you some more insight

http://blogs.msdn.com/michen/archive/2006/08/11/package-exec-location.aspx

Thanks

|||Via MSSMS, I logged directly into "Integration Services", and then successfully "Import(ed) Package", so it must be installed; ObjectExpolorer shows "DEVSQL06 (Integration Services 9.0.3054...). I don't have physical access to the machine, but am having somebody checking anyway.

|||Yep, see the post above. Sorry, I missed the part about you executing the package via SSMS. *You* don't have SSIS installed on your local machine.

If you were to create an Agent job on the server that pointed to the package, it would likely work fine.|||Karunakaran - Thanks..that definitely shed some light on the topic! I thought it was being run on the server via RPC, with status messages being returned back...

I do not have any SSIS Service on my machine, so will install it. (I do have SQLServer express, but am not using it).

However, just as a test, I removed the 'FileWatcher' control, then re-imported the package to the server, and it is now running (validation's all completed, and it has "Start"ed), and I see my recordcount increasing, so it is working. How is this possible if I don't have SSIS installed?

|||Because some components need to have a full version of SSIS installed. Just try it!

It's kind of a mess the way it's setup.|||

Only some components? I was under the impression to run a SSIS package you need to have full SSIS installed.

Time to dig up and see what all component will run without full SSIS installation. Is there any document on this?

Thanks

|||
Phil

Installation of SSIS on my PC did the trick; the Konesan FileWatcher task now works!


Karunakaran

Prior to installation of SSIS (when running my package with the Konesan FileWatcher removed), the package seems to have worked just fine with the following ControlFlow items:


For Loop Container
Execute T-SQL Task
Data Flow Task
File System Task

Your help is MUCH appreciated!!!

Rgds,
Allen

Custom Control Flow Item Issue

I've been using Konesan's FileWatcher control-flow item successfully in design-mode on my PC, which runs the package on a remote server.

I have installed the Konesan's FileWatcher on the remote SQLServer machine. I then imported the package to the server (Files System folder). I then select the package, right-click 'Run Package', then Execute, and receive the error:

"Error: The task 'File Watcher Task' cannot run on this edition of Integration Services. It requires a higher level edition"

..in the 'Package Execution Progeress' dialog. All other validation seem to be ok.

(Note, I'm executing the above steps using SQLServer Mgt Studio from my PC ; I'm not doing it from the SQLServer machine itself...not sure if this matters or not.)

The SSIS version installed on the server is 9.0.3054. It shouldn't be an "SSIS version issue", as it is the same SQLServer that I used (successfully) from my PC in design mode...

Thanks,

Allen

SSIS is not likely installed on the server. Grab the installation media and verify that SSIS is installed. Better yet, look at the services on the server and see if there's a SQL Server Integration Service.|||

When you execute from SQL Server Mgt Studio, actually it runs from your system and not on server. Hence you will need SSIS installed on your box to run it locally.

This should give you some more insight

http://blogs.msdn.com/michen/archive/2006/08/11/package-exec-location.aspx

Thanks

|||Via MSSMS, I logged directly into "Integration Services", and then successfully "Import(ed) Package", so it must be installed; ObjectExpolorer shows "DEVSQL06 (Integration Services 9.0.3054...). I don't have physical access to the machine, but am having somebody checking anyway.

|||Yep, see the post above. Sorry, I missed the part about you executing the package via SSMS. *You* don't have SSIS installed on your local machine.

If you were to create an Agent job on the server that pointed to the package, it would likely work fine.|||Karunakaran - Thanks..that definitely shed some light on the topic! I thought it was being run on the server via RPC, with status messages being returned back...

I do not have any SSIS Service on my machine, so will install it. (I do have SQLServer express, but am not using it).

However, just as a test, I removed the 'FileWatcher' control, then re-imported the package to the server, and it is now running (validation's all completed, and it has "Start"ed), and I see my recordcount increasing, so it is working. How is this possible if I don't have SSIS installed?

|||Because some components need to have a full version of SSIS installed. Just try it!

It's kind of a mess the way it's setup.|||

Only some components? I was under the impression to run a SSIS package you need to have full SSIS installed.

Time to dig up and see what all component will run without full SSIS installation. Is there any document on this?

Thanks

|||
Phil

Installation of SSIS on my PC did the trick; the Konesan FileWatcher task now works!


Karunakaran

Prior to installation of SSIS (when running my package with the Konesan FileWatcher removed), the package seems to have worked just fine with the following ControlFlow items:


For Loop Container
Execute T-SQL Task
Data Flow Task
File System Task

Your help is MUCH appreciated!!!

Rgds,
Allen

Friday, February 24, 2012

Custom Class for Function

I have several fuctions that I would like to share between my different script tasks in my SSIS package. I assume I do this by creating a custom class, but I cant quite figure it out. Can someone please point me in the right direction?

Thank You!!

Check Books Online under Programming Integration Services.|||

I didn't see any instruction for how to do this in the Books Online. If it is there, I can't find it. Please help, I would like to figure out how to do this.

Thank You.

|||

AspUser123 wrote:

I didn't see any instruction for how to do this in the Books Online. If it is there, I can't find it. Please help, I would like to figure out how to do this.

Thank You.

Assuming you know how to create an assembly, this explains how you can reference it from your SSIS scripts.

http://msdn2.microsoft.com/en-US/library/ms136007.aspx

Sunday, February 19, 2012

Custom Class for Function

I have several fuctions that I would like to share between my different script tasks in my SSIS package. I assume I do this by creating a custom class, but I cant quite figure it out. Can someone please point me in the right direction?

Thank You!!

Check Books Online under Programming Integration Services.|||

I didn't see any instruction for how to do this in the Books Online. If it is there, I can't find it. Please help, I would like to figure out how to do this.

Thank You.

|||

AspUser123 wrote:

I didn't see any instruction for how to do this in the Books Online. If it is there, I can't find it. Please help, I would like to figure out how to do this.

Thank You.

Assuming you know how to create an assembly, this explains how you can reference it from your SSIS scripts.

http://msdn2.microsoft.com/en-US/library/ms136007.aspx