SSIS 2012 Dynamic OLE DB ConnectionString using a parameter - connection-string

I have a project which I will need to deploy to servers not in our network and thus will not know certain attributes such as the server and database names. So I set up a parameter in the "Project.params" area. In this string parameter I placed: "Data Source=" + #[$Project::ServerName] + ";User ID=" + #[$Project::UserName] + ";Initial Catalog=" + #[$Project::InitialCatalog]; + "Provider=SQLNCLI11.1;Persist Security Info=True;" I copied the connection from the original one I set up before attempting this.
When I set the project level OLEDB Connection manager to this parameter in an expression (for the connection string), I get the string just as I typed and not the values of the other parameters. In other words when evaluated the expression appears just as above. Doing so invalidates all of the components in the package which use the connection. Any ideas on what I am doing wrong? Thank you in advance.

You cannot use multiple Project Parameters in a single parameterized OLE DB connection manager. Also, you cannot create a Project Parameter that dynamically builds on other Project Parameters, as they are read-only within a script task.
You would need to use a local (package-level) connection manager that uses a variable for its connection string. That local variable can be build on project parameter values.
Also see this post for a similar scenario:
Expression Builder of Connection Manager not showing Variables

Your connection string is missing the password field. I faced the same problem and adding the Password field that references to a variable/parameter fixed the problem for me. Also make sure the DelayValidation property is set to "True" for the Connection Manager.

Related

SSIS: Configuration of Dynamic Connection String Integrated Security Mode

Setup
In the local environments, we're using SQL Authentication with Username and Password to connect to the databases. I created a Project Connection Manager that has expressions bound to Project Properties, Username and Password being set to sensitive.
On the dev server, when the SSIS run, it needs to use an AD account. I might need to create a Credential/Proxy for the SQL Agent, but for now I'm logged in as the user and I execute the packag through SQL.
Problem
In the SSIS project itself, I'm trying to configure a dynamic connection string to use Integrated Security in one case, and SQL Account in another. I just can't figure out how to do it. Things I tried:
1- Created a boolean "UseIntegratedSecurity" parameter. In the connection string, use that bool to set IntegratedSecurity=SSPI or not with the expression, and also use expressions to set the other attributes of the connection string individually. It didn't work, said the connection string could not be built.
2- Created a boolean "UseIntegratedSecurity" parameter, and write my connection string as something (ugly) like: #[$Project::IntegratedSecurity] ? "Data Source="+#[$Project::SqlServerName]+";Initial Catalog="+#[$Project::SqlServerDatabase]+";Provider=SQLNCLI11.1;Auto Translate=False;Integrated Security=SSPI;" : "Data Source="+#[$Project::SqlServerName]+";Initial Catalog="+#[$Project::SqlServerDatabase]+";Provider=SQLNCLI11.1;Auto Translate=False;User ID="+#[$Project::SqlServerUsername]+";Password=" + #[$Project::SqlServerPassword]
It didn't work because since SqlServerUserName and SqlServerPassword are sensitive, it refuses.
3- Tried having Project Parameters for ConnectionString, Server, Database, User, Password and setting them all. Works locally, but on the server, I get "Invalid Authorization Specifications".
Ideas?
Thanks
You need to handle situation when in one environment you have to use SQL Authentication, and on the other - AD Authentication.
This can be done with help of SSIS Catalog Environment variables. When you create a Project file, Visual Studio automatically creates the following so called project connection parameters for each OLEDB connection manager :
CM.< conn manager name >.ConnectionString
CM.< conn manager name >.InitialCatalog
CM.< conn manager name >.Password Created as sensitive param
CM.< conn manager name >.ServerName
CM.< conn manager name >.UserName
OLEDB is an example, SSIS creates similar parameters for other connection manager types.
Important fact, you do not have to create additional project parameters. The parameters mentioned are created on project being built and are present on all projects.
We create environment variables which specify connection string, DB name (initial catalog), Server Name etc. Good thing - Connection string variable is applied first, and then amended with the other variables.
More details on these parameters is in MS Docs.
In case similar to yours, in Dev environment - using SQL Auth define Conn string for SQL Auth and specify username and password in corresponding variables. In QA env where SSPI is used - the Connection string is reworked for SSPI, UserName and Password environment variables are empty.

Trying to parse an SSIS connection string in Expression Builder

In SSIS I am using Project.params to parameterize a database connection string. Using the windows authentication this is simple, however I would like to do this with SQL authentication instead. The connection will be used in an Execute SQL task to execute a stored proc that just gets a list of data. Generating the parameter with SQL auth. The password is not stored (this is fine), so I added four parameters: Server, DBName, DBUser, DBPass. I want to be able to dynamically change any of these at runtime. So my thought was to build the connection string on the connection string property of the db connection manager. Issue is that it doesn't seem to want to validate. Here is an idea of what I'm trying to do.
Expression:"Data Source="+ #[$Project::ServerName]+";Initial Catalog="+ #[$Project::DBName]+";User="+ #[$Project::DBUserName]+";password=" +#[$Project::DBPassword]+";"
Sensitive parameters (the password) cannot be used in expressions. You will see an error message like this:
Expression cannot be evaluated.
The expression will not be evaluated because it contains sensitive parameter
variable "$Package::pw". Verify that the expression is used properly
and that it protects the sensitive information.
You can do as Nick suggested and parameterize the connection manager directly. I would suggest only parameterizing the connectionstring and password (separately). This would allow you to alter between windows and sql authentication.
i.e.
Windows:
Connectionstring: Data Source=;Initial Catalog=;Provider=SQLNCLI11.1;Integrated Security=SSPI;
Password: leave blank
SQL:
ConnectionString: Data Source=;Initial Catalog=;Provider=SQLNCLI11.1;User Id=
Password:

Dynamic datasource in SSRS

I am working on a report which will pull all sysadmin login's from each server. So I used below data source properties and created parameter names:
servername ="data source=" & Parameters!Servername.Value & ";initial catalog= master"
above solution working fine in SQL Server Data tools but when I deploy in report server I am getting error on connection error's like below.
An error has occurred during report processing. (rsProcessingAborted)
Cannot create a connection to data source 'dSource_DbOwner'.
(rsErrorOpeningConnection) Format of the initialization string does
not conform to specification starting at index 0.
Please let me know all your inputs
Thanks, Ven
SSRS can be annoying sometimes with plain text. I would suggest going into the connection manager and using the wizard. I believe it is a button with build on it to the top right hand side of where you are inputing this text. That will create the connection easily and it wont spit and sputter at the connection string.

Dynamically assign filename to excel connection string

This is my very first time playing with SSIS in SQL Server 2012. I can successfully read an excel file and load its content to a table in SQL server 2012. The task is a simple direct read excel file then copy to sql server with no validation or transformation for now. The task was successful. But when I tried to make the package read the file name from a variable instead of the original hard coded one, it was generating an error "DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E4D"
What I did was just replacing the hard coded connection string in the excel connection manager with an expression which took the value of a variable assigned by an expression
The variable was assigned the value before the data flow task started. The variable was checked and did have the correct value.
But the error below was generated when data flow task started.
It would be highly appreciated if someone could point out what I did incorrectly and advise me how to solve the issue.
Option A
The ConnectionString property for an Excel Connection Manager is not where I go to manipulate the current file, which is contrast to an ordinary Flat File Connection Manager.
Instead, put an expression on the Excel Connection Manager's ExcelFilePath property.
In theory, there should be no difference between ConnectionString and ExcelFilePath except that you will have more "stuff" to build out to get the connection string just right.
Also, be sure you're executing the package in 32 bit mode.
Option B
An alternative that you might be running into is that the design-time value for the Connection String isn't valid once it's running. When the package begins, it verifies that all of the expected resources are available and if they aren't, it fails fast rather than dieing mid load. You can delay this validation until such time as SSIS has to actually access the resource and you do this by setting the DelayValidation property to True. This property exists on everything in SSIS but I would start with setting it on the Excel Connection Manager first. If that still throws the Package Validation Error, try setting the Data Flow's delay validation to true as well.
I had a heck of a time trying to get this to work, even after following all the instructions, so I just kept it with a static excel name and added a “File System Task” to copy the file and create a new file with whatever name I need.
We can define our connection string like below in Expression:
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + #[User::InputFolder] + "\\"+ #[User::FileName] +";
Extended Properties=\"EXCEL 12.0 XML;HDR=YES\";

Using Dynamic Connection Strings in SSRS2008

I have a bunch of SSRS 2008 reports which I'd like to run on several different machines (development, test, production). Each machine has it's own database, so I need to use different connection strings depending on where the report is running.
One workaround I found is to specify the server and catalog name in a hidden parameter that is passed to the report at runtime. It's described in this tutorial, but it applies to SSRS 2005 and I could not make it work in SSRS 2008.
Everything works fine when the connection string in my shared datasource looks like this:
Just so to see if expressions can be used at all for the connection string, I replaced the connection string with this:
But this gives me the following error when I try to preview the report in Visual Studio:
An error occurred during local report
processing. The item
'/Zeiterfassung-Adrian' cannot be
found.
Are dynamic connection strings still working in SSRS 2008?
If yes, what am I doing wrong?
If not, what else can I do?
It's because it's a shared datasource. Should work fine for a regular embedded datasource. Take a look at THIS link for an option on using dynamic connections strings with shared datasources, might be helpful for you.
Just create your report datasource for each environment and deploy them. Then switch your deploy option to not overwrite a datasource. Though to make for simple deployments you will have to configure the configuration manager in bids for each environment. This is how we work in our multiple environments.
Hope it helps, let me know if you have any questions on this.
Please check related article at
http://haseebmukhtar.wordpress.com/2011/11/09/dynamic-database-in-ssrs-2008/
Also you can not use dynamic database settings for the shared data source.
The string should have double double quotes for server name.
="data source="" & Parameters!MyServerParameter.Value & "";initial catalog=DBName.."
I was able to create a dynamic embedded connection using a ServerName parameter as follows:
="data source=" & Parameters!ServerName.Value & ";initial catalog=master"
What about using a hidden report parameter?
then you should be able to do:
="data source=" & Parameters!MyServerParameter.Value & ";initial catalog=DBName.."
Here is an article which should help you out: http://msdn.microsoft.com/en-us/library/ms156450.aspx

Resources