简体   繁体   中英

C# - Running a SSIS on a SQL Server from a wpf Application

I cannot seem to find any useful documentation for the specific situation i need. I am trying to Launch and pass variables into an SSIS package that is deployed on a sql server.

In management studio the package can be found under Integration Services Catalog\\SSISDB\\IhsDataSync\\Projects\\LoadHeader\\Packages\\Package.dtsx . From the sources I have found it appears that I need to use the Microsoft.SqlServer.Dts.Runtime; assembly. When I go to write the rest of the code is where i am having thousands of questions.

So far I have:

            try
        {
            Application app = new Application();
            Package package = null;

            package = app.LoadFromSqlServer("SSISDB\IhsDataSync\Projects\LoadHeader\Packages\Package.dtsx","servername","username","password",IDTSEvents);
        }
        catch
        {

        }

Most examples only show how to load a local package in which case the first method parameter is quite obvious. What is the path for using a package on the sql server?

What is the last parameter of LoadFromSqlServer() --> IDTSEvents??? How do I inject variables?

Can you call dtexec from a shell? If you use this approach you lose the exception hooks you get with the pure programmatic approach but passing values into ssis variables is as easy as /SET You can still interrogate the return code for success. It might do as a workaround.

I gather that the primary question you are asking is how you can assign values to Variables before execution? If so, you can use the respective DtsContainer (or its child) object to access the variables and then assign the value to a specific variable.

Let us say you have variable with the name "ABC" in the namespace "User" on the package itself. You can do this:

package = app.LoadFromSqlServer("SSISDB\IhsDataSync\Projects\LoadHeader\Packages\Package.dtsx","servername","username","password", idtsEvents);
package.Variables["User::ABC"].Value = <value of approproate type>

If your variable is associated to a child container or task, then you can obtain a reference to that sepcific container/task and then access the Variables property like the above example.

The last param of the LoadFromSqlServer is for you to access Events that can happen as part of the Load call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM