Dynamically set connection string of SSIS package through cmd - ssis

I am trying to dynamically set the connection string of my SSIS package through DTEXEC.exe
My CMD file consists of following command.
"C:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTEXEC.exe" /f
"D:\ABC\XYZ\Packages\ABCD.dtsx" /CHECKPOINTING OFF /REPORTING V /CONSOLELOG/Conn
"Configurations;'"Data Source=XXXXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;Integrated
Security=SSPI;Auto Translate=False;'"" /SET
"\Package.Variables[User::TargetEnvironmentId].Properties[Value]";"2"
If i take out connection string part it works fine but when i add
/Conn "Configurations;'"Data Source=XXXXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;
Integrated Security=SSPI;Auto Translate=False;'""
This it throws exception and says INVALID

Is the name of your connection manager called "Configurations"? I can only assume that is the case. Give the following a try:
/CONNECTION "Configurations";"\"Data Source=XXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;\""
I always find it easier to use DTExecUI to create the script, have you tried doing that?
Either that or set the connection string as a variable and pass that through DTExec

Related

SSIS 2008 Execute Package Task Connection Expression not valid

In SSIS 2008 I am trying to configure a package to execute another package using the Execute Package Task. In the Execute Package Task Connection expression I am using a variable that contains the absolute path to the folder where the package I want to execute is located because as we all now relative paths don't work in SSIS. The expression evaluates to what looks to be the right path as can be seen in the screenshot below.
However when I try to execute the package I get the following error that it can't find the package:
I am very confused by this because the package path is correct. Any ideas?
I think you are setting the connection in the wrong place.
You need to set the connection string in the connection manager.
Example that I want to change the Package1.dtsx to execute Package2t.dtsx ..
Created Connection Manager "Package1.dtsx" that references a package in a folder called Package1.dtsx
Properties of Connection of Package1.dtsx in Connection Manager
Change ConnectionString in Connection Manager to execute Package2t.dtsx.
Try including double quotes since your file path string has spaces in it
"\"" + #[User::RootFolder] + "\\" + "ImportSessionAndSubsessions.dtsx\""

Passing connection string properties when using DTEXEC

I am wondering what the correct format is for passing connection string properties on the command line when using dtexec:
dtexec.exe /Ser IpAddress\Instance /IS "\SSISDB\Data Warehouse\MyProject\MyPackage.dtsx" /DumpOnError /Set \Package.Variables[DW_ConnectionString].Properties[Value];\""Data Source=IpAddress;Initial Catalog=DWDB;Provider=SQLNCLI10.1;IntegratedSecurity=SSPI;"\"
I have defined the above command line configuration where I am attempting to pass override properties for the default connection string properties. The packages I'm targeting are not using package connections, but instead project level parameters/properties have been defined to store the DB connections.
For some reason I can't get this to work . I am getting an error message on the server saying
Failed to configure an overridden property that has the
following path: \Package.Variables
[DW_ConnectionString].Properties
[Value]. An error occurred while setting the value of
property "Value". The error returned is 0x80020009
Is my format correct for overriding properties?
The packages are hosted on a remote server
Try using DTEXECUI next time to generate your command string. It has places for all of the variables, connection managers etc. All you have to do is bring up your package and it fills everything in. You then enter any changes you want in the GUI then go to the Command line tab and it will give you the string to put after DTEXEC.EXEC. You can of course also run the package from DTEXECUI also.
It turns out that my format was wrong:
It's incorrect to use /Set Package Variable in this context:
The correct format is:
/Par "$Project::DW_ConnectionString";\""Data Source=Server\Instance;Initial Catalog=myDb;Provider=SQLNCLI11.1;Integrated Security=SSPI;AutoTranslate=False;"\"

How to use DontSaveSensitive and xml configuration file during SSIS package development

Is it somhow possible to set the ProtectionLevel of SSIS package to DontSaveSensitive and to use connection string with password from configuration file during package development in Visual Studio?
I have package e.g. Package1 with ProtectionLevel = DontSaveSensitive. This package is using connection from connection manager e.g. Connection1.
Package1 has configuration enabled using configuration file file1.dtsConfig with connection string specified. This connection string has the password in it:
<DTSConfiguration>
<DTSConfigurationHeading>
<DTSConfigurationFileInfo GeneratedBy="..." GeneratedFromPackageName="..." GeneratedFromPackageID="..." GeneratedDate="20.3.2013 12:08:27"/>
</DTSConfigurationHeading>
<Configuration ConfiguredType="Property" Path="\Package.Connections[Destination].Properties[ConnectionString]" ValueType="String">
<ConfiguredValue>Data Source=.;Password=Password123;User ID=MyUser;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;</ConfiguredValue>
</Configuration>
</DTSConfiguration>
Now when opening the connection from connection manager in Visual Studio, the text field for Password is left blank and the package doen't execute. Why wasn't used the password specified within the connection string in configuration file file1.dtsConfig?
Finally we found a way how to do it:
Change ProtectionLevel to DontSaveSensitive
Create configuraton file with connection string
Manually edit this configuration file: add the password to the connection string in case you connect with SQL Server authentication
Then SSIS package will load the connection string inclusive password from the configuration file even in Visual Studio. In connection manager-connection dialog the password will not be shown, but the package runs using connection string from configuration.
SSIS will take the connection string from the Config File only during the runtime.Even if you mark the checkbox Save my Password , SSIS won't save the password value.This option is vald only during the BIDS session. So the next time when you open the package using BIDS ,again you need to enter the credentials in Visual Studio else the package won't compile ,But the package will always execute properly during run time if you have specified the connection string in config file.
As per MSDN it clearly states that
Do not save sensitive : prevents properties that are marked sensitive
from being saved with the package and therefore makes the sensitive
data unavailable to other users.
This is the case also when package has been set at first to use EncryptSensitiveWithUserKey, then changed to DontSaveSensitive -protection level. You must manually edit .conmgr-file and remove DTS:Password element and put the password into connection string, as user dee has wisely written above.

execute package with .net and Job

is it possible to execute a Package with both a job and from .net?
how to change the input parameter?
Yes you can execute the SSIS packages using SQL Agent and from a .NET application.
If you need to pass the input parameter then you need to use the SET option while executing through DTEXEC command line
/SET "\Package.Variables[User::YourVariable].Properties[Value]";"ValueToBePassed"
If you have several parameters to pass then you can use the above the query in a text file and then use the CommandFile option in DTEXEC
DTEXEC /File "C:\Package.dtsx" /CommandFile "C:\inputOptions.txt"
If your running from .NET .Add a reference to Microsoft.SqlServer.Dts.Runtime.Application
using app=Microsoft.SqlServer.Dts.Runtime.Application;
string pkgLocation;
Package pkg;
DTSExecResult pkgResults;
pkgLocation = #"C:\SSISPackage\YourPackage.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);
pkg.Variables["VariableName"].Value = "VariableValue";
results= pkg.Execute();
Refer my answer in SO.I have used a script task to execute the package but you can use that code in your .NET app
Refer this article for further information

Override SSIS configuration setting on command line?

I'm trying to run an SSIS package from the SQL Server Management Studio, and am having trouble overriding a configuration setting. In my case, it's the location of a flat file. The command I'm using is:
declare #returncode INT
exec #returncode = xp_cmdshell 'dtexec
/SQL "\ImportData"
/SERVER "myserver"
/CONNECTION "ImportData flatfile connection";"C:\files\ballot.dat"
/MAXCONCURRENT " -1 "
/CHECKPOINTING OFF /REPORTING E'
As you can see above, I'm trying to run this using c:\files\ballot.dat as the flat file in question. When doing so however, SSIS reverts to using the setting stored in its configuration file, which points to a different location (and ballot.dat file) on the hard drive.
Is there a way to override that when calling the package from the command line? Thanks for your suggestions.
What you can do is to add an SSIS Package configuration XML file. In this configuration you can specify all connection managers (just include the connection string). save this file as c:\otherconfig.xml or something like that. Edit the file, you should see your connection listed, and you can edit the connection string.
When running the package with dtexec you should be able to run it with that config file using /configuration.
Note also that there are lot of changes from 2005 to 2008 in how connections and package configurations are handled. See http://msdn.microsoft.com/en-us/library/bb500430.aspx for more details.
You need to set the *full" connection string, not just the file name...
/CONNECTION "ImportData flatfile connection";"Provider=...;Data Source=C:\files\ballot.dat"