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.

Martin Carlsson
  • 461
  • 2
  • 6
  • 18

1 Answers1

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.

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66
  • 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".` – Martin Carlsson Jun 27 '16 at 14:27
  • 1
    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. – Martin Carlsson Jun 27 '16 at 14:35
  • 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! – Bacon Bits Jun 27 '16 at 14:36