Running a SQLCMD script from SSIS Execute Process Task with variables

我的未来我决定 提交于 2019-12-02 20:55:58

问题


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.

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:


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.



来源:https://stackoverflow.com/questions/38056374/running-a-sqlcmd-script-from-ssis-execute-process-task-with-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!