SSIS Parameters cannot be resolved by dtexec - sql-server

I am trying to set a parameter while executing a package from command line
dtexec /f mypackage.dtsx /set \package.variables[$Project::MRNS_Database].Value;myvalue
I get the below error
The package path referenced an object that cannot be found:
"\Project.Variables[$Project::MRNS_Database]". This occurs when an
attempt is made to resolve a package path to an object that cannot be
found.
In fact the MRNS_Database is actually a parameter set at project level (I can see this under Parameters in Package Explorer). Also I am not able to use the /Par switch as i am using /File option.
How do i set the parameter in this case from command line dtsexec?

You have to specify ISPAC Project file as well, like this example
DTEXEC /Project "Path to proj\YourProj.ispac" /Package "yourpackage.dtsx"
/Set \Package.Variables[$Project::MRNS_Database];yourvalue
More details in Microsoft dtexec Reference.

As Ferdipux points out you need to reference your ispac file. Make sure you have builed your project otherwise it can cause errors.
Make sure everything is on ONE line if you use bat file.
I also included package parameters if you have those.
Bat file
#ECHO OFF
ECHO.
ECHO This is a batch file
ECHO.
DTEXEC.EXE /Project "C:\Users\thoje\Documents\Visual Studio 2015\Projects\Integration Services Project8\Integration Services Project8\bin\Development\Integration Services Project8.ispac" /Package Package24.dtsx /Set \Package.Variables[User::Test3].Value;1 /set \Package.Variables[$Package::Test2];1 /set \Package.Variables[$Project::Test4];1
PAUSE
CLS

Related

dtutil import ssis package from remote

I am trying to import an ssis package (.dtsx) from one server to another remotely but I face a strange issue. (dtsx is on Server-02 and need to be imported on Server-01)
Let me explain with 3 commands :
Running on Server-01
osql -E -h -Q "select name from [msdb].[dbo].[sysssispackages] where name like '%MIC%'"
This returns nothing, my package is not imported yet, that's ok.
I have a .bat file on Server-01 which contains the following command :
"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET
DTSX is located in D:\ on Server-02, .bat file is located in D:\ on Server-01.
This bat file must be run in order to import the ssis package.
Then running on Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
It returns successful state. But then when I run again on Server-01 my osql command, it still returns 0 result. It seems the package hasn't been imported...
We could think that the bat file isn't working but if I run the bat file directly by double clic on Server-01, it also runs successfuly. Then I do the osql select, it returns 1 result, the package has been imported successfuly.
At this moment, I thought that the bat script was simply not executed remotely. So I changed it a little.
echo "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET > D:\debug.txt
Then from Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
D:\debug.txt has been successfuly created on Server-01 which means the bat script also executed well...
Any idea of what could happen in my case ?

DTExec.exe CheckFile and Validate fails

I'm trying to execute a dtsx script using DTExec.exe as part of the batch process. The following command line script works:
"C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe" -File "\\\\vm-to-somewhere\d$\Projects\test.dtsx"
However, if I try to run a check/validation on the test.dtsx file before actually running the script, it fails with an exit code of 6 (which translates to: The utility encountered an internal error of syntactic or semantic errors in the command line).
$ "C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe" -CheckFile "\\\\vm-to-somewhere\d$\Projects\test.dtsx"
$ "C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe" -Validate "\\\\vm-to-somewhere\d$\Projects\test.dtsx"
Returns: Option "\\\\vm-to-somewhere\d$\Projects\test.dtsx" is not valid.
It's probably just a simple mistake I'm overlooking, and I was wondering if it was something with the backslashes but the first command runs fine so it doesn't make sense.
Also, if someone could point out to me the differences between -CheckFile and -Validate, that might help me decide which to use in my script. I just need to know if the dtsx works fine before executing it because it takes 3hrs to run and I prefer to find out sooner rather than later.
References: https://msdn.microsoft.com/en-us/library/hh231187(v=sql.110).aspx
You missed "-File" (or "-f") option just in front of your package name
It should be like
DTExec.exe -f "<package name with path>" -Validate
Note that the package may have a configured delayed validation, so -Validate option won't validate the items with delayed validation. There are options to enforce a validation of items with delayed validation, but this is a separate topic.

How can I remote run an SSIS package using DTEXEC?

I'm very new to using dtexec and to deploying SSIS packages (mostly just run them in VS). I would like to remote run a package that I have deployed to a server using DTEXEC...
The package name is SQL2012 Update Run. When I open up SSMS, the package is found under
Integration Services Catalogs -> SSISDB -> ServerUpdate -> Projects -> UpdateRun -> Packages -> SQL2012 Update Run
The server name is 1555\C1592.
I have tried all sorts of variations on using the /sql command, the /ser command, /dts, /file, I just can't seem to get it to run.
How would I use the dtexec utility to run the package at the specified location using integrated security?
Edit: Oh and there are 4 parameters, 3 are strings and one is an int16, how would I pass these in?
Thank you
Below is an example of how write dtexec with the dtsx file location and variable input.
example:
dtexec /F "C:\Temp\Test.dtsx" /SET \Package.Variables[User::Guess_A_Number].Properties[Value];3
Shell (Edit):
dtexec /F "<your_directory/<your_file>.dtsx" /SET \Package.Variables[<Your Variable>].Properties[Your Value];<Your Value>
Explanation:
/F is the location of your dtsx (SSIS) package
/SET to set your variables.
More info on dtexec:
TechNet Link
Hope this helps!

SQL Server agent for scheduling SFTP using WinSCP under SSIS

I have a batch script which generates a WinSCP upload script to upload a file to an SFTP location. Now when I run the batch file via command prompt - it runs successfully and loads it. I called the same thru SSIS Execute process task - it runs successfully and loads it. Now when I put the same on SQL Agent - I tried the following two options:
Using Operating System (CmdExec) - cmd.exe /c "\.bat"
Added the SSIS package to SSISDB and added it as a job step.
With both the above options the job showed a successful run. However the file is not uploaded! Any ideas on what is happening?
Here's my batch script:
echo off
SET winscp=C:\"Program Files (x86)"\WinSCP\WinSCP.com
SET stagingDirectory=\\<staging path>\
SET scriptPath=\\<ScriptPath>\UploadScript.txt
SET ftpHost=xx.xx.xx.xx
SET ftpUser=user
SET ftpPass=password
SET fileName=Test.xlsx
SET ftpFlags=
#REM ftpFlags: -explicit
echo deleting uploadScript if it already exists
IF EXIST %scriptPath% del /F %scriptPath%
IF EXIST %scriptPath% exit 1
echo Generating WINSCP Upload Script
>>%scriptPath% echo option batch abort
>>%scriptPath% echo option confirm off
>>%scriptPath% echo open sftp://%ftpUser%:%ftpPass%#%ftpHost% %ftpFlags%
>>%scriptPath% echo option transfer binary
>>%scriptPath% echo put %stagingDirectory%%fileName% /
>>%scriptPath% echo close
>>%scriptPath% echo exit
echo Launching WINSCP upload
start /wait %winscp% /console /script=%scriptPath%
As you start the WinSCP via the start (why?), the exit code is not propagated to the SSIS. So, you never learn, if the script fails. And it most probably fails.
You also should enable logging, so that you can see what's wrong.
You should use this code to propagate the WinSCP exit code to SSIS and to enable logging:
%winscp% /log=\\<ScriptPath>\UploadScript.log /script=%scriptPath%
exit /b %ERRORLEVEL%
(Note that the winscp.com does not have the /console parameter)
Anyway, one clear problem is that you do not specify an expected SSH host key in the script. When you run the script manually, you probably have the key cached in the registry of your Windows account. But under the SSIS a different account is used, and its host key cache is likely empty. You should add the -hostkey switch to the open command in the script to make the script independent on the cache. See Where do I get SSH host key fingerprint to authorize the server?
When testing the script, add the /ini=nul parameter to isolate the script from your configuration.
For this and other hints, when debugging WinSCP running under SSIS, see My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong?
And finally, see WinSCP SFTP Task for SSIS.
Your variable seems set incorrectly. To manage with a space in the path and into the variable you have to put in quotes the whole path or the whole variable.
i.e.
set "winscp=C:\Program Files (x86)\WinSCP\WinSCP.com"
echo start "%winscp%"
:: output: start "C:\Program Files (x86)\WinSCP\WinSCP.com"
or
set winscp="C:\Program Files (x86)\WinSCP\WinSCP.com"
echo start %winscp%
:: output: start "C:\Program Files (x86)\WinSCP\WinSCP.com"
Another point, you have to check this file: UploadScript.txt because your script adds new lines rather than remake the file.
change this line to >%scriptPath% echo option batch abort instead of >>%...
Ah, I did not pay attention to the IF EXIST.

How to create a Simple Build Script for Visual Studio from the Command Line?

I have a lot of Visual Studio Project Solutions in multiple directories (all with the extension .sln) and I want to write a simple batch script that will automatically build all solutions listed in the batch file.
I am able to manually build a solution by starting up the Visual Studio Command Prompt (which is just a command-line instance with the following command executed
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
After which I then build the project by calling:
devenv "path\to\solutionFile\projectSolution1.sln" /build Debug
This will build the project (assuming the project does not have errors) and I rinse and repeat for each project I want built.
However when I have the following in a batch file called build.bat:
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo "Starting Build for all Projects with proposed changes"
echo .
devenv "path\to\solutionFile\projectSolution2.sln" /build Debug
devenv "another\path\to\solutionFile\projectSolution3.sln" /build Debug
devenv "yet\another\path\to\solutionFile\projectSolution4.sln" /build Debug
echo "All builds completed."
pause
The batch script only executes the first line, and waits until I type in exit before executing the others. My understanding of this based on the research I have done on batch files and all the StackOverflow questions is that cmd actually invokes another instance of itself that executes vcvarsall.bat to set up the build environment.
This will not work as typing exit kills that instance with devenv set up and the commands after that cannot execute as devenv is not a recognized command (since the exported path will not exist anymore)
In short, how can this be achieved (passing in the rest of the commands to the cmd instance with devenv defined) in a single batch file? I understand this isn't a robust way (and there are a lot of tools that do this) of invoking builds but I'm just hoping to have one batch script to automate the manual work of individually calling these projects.
Found the solution, as noted by Jimmy, one needs to remove the environment variable %comspec% as that is a shortcut to CMD.exe.
However, just removing "%comspec" /k will cause a CMD instance to open and then exit after a second. I also previously tried the call function which created a separate CMD instance when used with %comspec%
The solution is to add call in front of the first line, and remove %comspec
Here is the final batch file that got things working as intended.
#echo OFF
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo "Starting Build for all Projects with proposed changes"
echo .
devenv "path\to\solutionFile\projectSolution2.sln" /build Debug
devenv "another\path\to\solutionFile\projectSolution3.sln" /build Debug
devenv "yet\another\path\to\solutionFile\projectSolution4.sln" /build Debug
echo .
echo "All builds completed."
pause
Note that #echo OFF tells the batch script to not echo out the commands (such as that call command) into the terminal (errors and warnings will still be shown, however)
If this is already in a batch script, then this line:
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Probably should just be "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Why? %comspec% is just an environment variable shortcut to cmd.exe, so as you saw, it's launching a new instance of cmd with the /k option specified (which if you run cmd /? says Carries out the command specified by string but remains). You don't care about it remaining, you don't even want a new cmd.exe when you're already running your batch file.

Resources