1

I have an .sql file with scripts that include SQLCMD elements.

I need to have it run from an SSIS package.

I was unable to execute it from an "Execute SQL Task".

According to this http://www.sqlservercentral.com/Forums/Topic818940-147-1.aspx I should use an "Execute Process Task" with:

Executable: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
Arguments: -S server -U user -P pass -i C:\path\to\file.sql

This is working fine.

But, I need the Arguments to include a Variable. What ever I try, it is failing.

Execute Process Task

Arguments: -S server -U user -P pass -i @[User::FileNameView]

The error:

[Execute Process Task] Error: In Executing "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" "-S server -U user -P pass -i @[User::FileNameView]" at "", The process exit code was "1" while the expected was "0".

My questions is: how do I include a variable in the Arguments string? Is there a different approach I should take?

Extra info:
SQL Server 2008R2
The reason I need this to be a variables is because I will put the "Execute Process Task" in a "For each loop" to be able to execute all .sql files in a folder.

1 Answer 1

2

I believe you need to create an expression named Arguments with the value:

"-S server -U user -P pass -i " + @[User::FileNameView]

You may need to do some type casting if @[User::FileNameView] isn't a string.

Sign up to request clarification or add additional context in comments.

3 Comments

This is the error I get when I try that: [Execute Process Task] Error: In Executing "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" ""-S server -U user -P pass -i " + @[User::FileNameView]" at "", The process exit code was "1" while the expected was "0".
Arh - you are correct! I have not used "Execute Process Task" before - so I misunderstood what you ment with an expression. It is working correctly now. Thanks.
Ah, yes, I was debating if I should explain what to do or not in better detail. Glad you were able to figure it out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.