0
votes

I want to execute SSIS package using command line arguments. As we can do it in executing C# project. And i want to use that argument.

CmdLineArguments: INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014

And then i want to use these different vlues to do some operations.

What I have got: I searched on line and got that we have to give something like below

dtexec /file Package.dtsx /Set \Package.Variables[User::UniversFileAddress].Properties[Value];\" INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014\"

which have no effect on execution. i mean it's not working for me. May be my concept is wrong.

whereas i want to pass arguments as below

INTRADAY OPT OPTION_DAILY_INTRADAY_VOL12/02/2014

And use these arguments in script task. How can i do so..?

1
I do not understand people just give points down or up instead of helping someone or giving some helpfull answers. Do they think they are superioer ..? I mean what's wrong with this quetion..? i tried alot and if i couldn't get the answer then i posted..Nitesh Kumar SHARMA
The easiest way to figure out the syntax needed for your command line string is to create an agent job that calls the package and fill in the variables on the configuration tab. Now script out that agent job and take a look at the @command parameter.Data Masseur
@DataMasseur thanks for your help . Can you please tell me more about what is an agent job..?Nitesh Kumar SHARMA
SQLServer Agent is a built in part of SQL Server that runs as a service (although it isn't always enabled.) If you have SQLServer Management Studio, when you connect to a database, it shows up in the object explorer and there's a "jobs" subfolder under it. Here's a decent link with more details: answers.oreilly.com/topic/1568-how-to-use-sql-server-agentData Masseur
@DataMasseur Yeah now i gpot it. But i think i will go in wrong direction. Actually the thing is my manager wants me to give him the ssis package as he wants to use as below. 1. Give some arguments to the CmdLineArguments and use that in package. 2. Create a xml config file where i can set the input and output paths. And then he will use it in his project accordinglly and he will use sql aget to run it but i am not allowed to do it. So now i don't know how to use config file. And how to use given arguments in the package. How can i acces themNitesh Kumar SHARMA

1 Answers

0
votes

There are many ways actually but i found following way suitable for my application.

  1. Create a console application.
  2. Call that ssis package in that application.
  3. And you can set varible values in that console application

here is the code:

using Microsoft.SqlServer.Dts.Runtime;

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] argsArray = new string[] {"","","","" }; if (args == null) Console.WriteLine("args is null"); else { if (args.Length > 4) {

            }
            else if (args.Length > 3)
            {
                for (int i=0;i<args.Length;i++)
                {
                    argsArray[i] = args[i];
                }

            }

        }

        string pkglocation="h:\\My Documents\\Visual Studio 2008\\Projects\\Try_Project_To_Convert_Fro_Asia_Euro_US\\Try_Project_To_Convert_Fro_Asia_Euro_US\\Package.dtsx";

        Application app= new Application();

        Package Pkg=app.LoadPackage(pkglocation ,null);
        Pkg.Variables["User::fileName"].Value = argsArray[2] + argsArray[3].Substring(6, 4) + argsArray[3].Substring(3, 2) + argsArray[3].Substring(0, 2);
        string test = (string )Pkg.Variables["User::fileName"].Value;
        Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = Pkg.Execute();


    if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
    {
        string err = "";
        foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in Pkg.Errors)
        {
            string error = local_DtsError.Description.ToString();
            err = err + error;
        }
    }
    if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
    {
        string message = "Package Executed Successfully....";
    }

    }
}

Please let me know if you have any problem