SSIS with variable excel connection manager - excel

I am trying to do automatic package execution with a WMI Event Watcher Task within SSIS. The functionality I want is automatic package execution when excel files are dropped into a certain folder. However, these excel files will be the connection managers for populating a database.
Currently SSIS will not allow me to do this because my excel connection manager does not have a path when I run the program, and only exists once the files are dropped in the folder.
Is there a way for variable excel connection managers or the value of the connection string to be a variable?
Also, how do I implement the usage of this variable in an expression?

You can use a variable for the connection string of you excel source:
Click on your Connection manager of your excel source
In properties window, add an expression(1) ConnectionString(2) and assign a variable(3)
There are alot of different things you can do with variables. They are used alot in combination with for each loop containers and file system tasks. Your normally do something like this
create a variable in variable window
Set a static value or one that gets changed during the package flow
Map the variable to an expression
There are alot howtos on the web, maybe have a look at this to get warm with it:
http://www.simple-talk.com/sql/ssis/working-with-variables-in-sql-server-integration-services/
http://www.rafael-salas.com/2007/03/ssis-file-system-task-move-and-rename.html

The fastest way i know to achieve this is by creating an excel connection manager and setting its connection string through a variable. In order to do so you will need to make the connector first by pointing it to an excel file. It doesn't matter which, since you will be dynamically setting the new file in runtime. Then, select your excel connection manager and check its properties. You have a ConnectionString property, which you can set through an expression.
However, you must make sure that your package will only use the Excel Connector after it has been filled with the correct connection string!
For further information on SSIS variables check this link: Variables in SSIS

Related

ssis - how to parameterize excel connection

I need to load a .xlsx source to do some things. I've made an Excel Connection Manager and it works but I need to parameterize it to use a dynamic path. How can I do that? I've read a lot of guides but I couldn't get it to work. How do I define the path variable and how do I use it?

Automation - Replace Connection Properties on Excel

I'm currently working on maintaining some old (new format .xlsx) excels with more than 60+ connections each that feed some various tables from a SqlServer.
I'm in search of some kind of toolkit, module, standalone script (or anything really) that let me bulk change the command text inside each connection properties.
The change should be not harder than changing part of the table name as the new table only contains the information that the table needs.
So far, the only thing that gets near what I need are those python modules but they don't appear to implement anything for handling connections.
Thank you in advance for any help you can provide.

Though deprecated, is DAO still used for automation of Access databases from Excel?

I'm trying to wrap my head around it. I've checked other questions and nothing seems to be too similar.
The Office 2013 development centre contains extensive DAO examples and states it is one of the easiest ways to work with an Access file (does not require an Access window) but DAO is a deprecated technology. (https://msdn.microsoft.com/en-us/library/office/ff834801.aspx)
I'm trying to write an Excel Add-in (eventual end point) that will grade Access assignments in .accdb format.
I'm can't just use ADODB to perform SQL queries to extract data, unless SQL can also do the following:
check a specified report has a specified title
check that specified tables, queries, forms, and reports exist
check specific fields in a table exist
check that specific fields have been set as the Primary Key
I also need to check that certain values exist in a table, but those I can solve with SQL.
So should I be using DAO or stick with ADODB? Remember, I'm using Excel, not programming in Access VBA.
The simplest way to work with excel tables is to link them in Access either manually or via the TransferSpreadsheet function in VBA. If you use a generic naming standard for the file names and tab names in Excel, you will not have to relink, rather you can replace the Excel file and the Access link will read the new file unless the layout has changed.
Once linked you can use the query-by-example tool to write your queries which also can be written into code (i.e. either embedded in the VBA [old school and not a best practice] or saved in an Access table then looked up and assigned to a variable for use with the CurrentDb.Execute strSQL, dbFailOnError command.
I suggest manually linking the first go round so you can manually define the individual column types vs. letting Access mess it up.
If you cannot use generic names and have to pick the file via a browse dialog, you can get a file browse function via Google to allow you to programatically link the file. (or you can rename it to a generic name which works even better)
So DAO vs. ADODB is moot from an Access perspective. I supported 50 databases with 70,000+ lines of code and dozens of Excel source files the past 4 years and never had to ponder the question.
Microsoft originally deprecated DAO in favor of ADO, but recently renamed DAO to Microsoft Access Engine (ACE) and is now pushing it as the preferred data access technology for Automation-supported environments (VBA, WSH etc.)
In general, in your scenario I don't think it makes much of a difference which one you use. I suggest you read through this.
I don't think it's possible to read table/query/field information via SQL. However, this can be done either with the DAO.TableDefs and DAO.QueryDefs collection, or the ADO.OpenSchema method.
RE: forms/reports - I don't know if it's possible to read form/report information via DAO or ADO even without SQL, as it is actually part of the UI objects, and not the data; unless we're talking about reading/parsing the system tables. You may have to open the database in a hidden Access instance and read the forms/reports that way.

Programmatically change crystal rpt connection

I'm trying to find a way to Programmatically change the connection string of an rpt file permanently to a connection that currently doesn't exist. I need to send these rpt reports out to clients who are using a different connection then I am.
I've tried some examples where you load the report and then set the connection with apply logon info, but it seemed to only affect the report at run time and the changes never stayed. I need the rpt file to keep the connection string i set.
Is there an way to do this?
You need to call the method SaveAs of the ReportDocument class.
If you need to change just one file you can use this tool instead of writing your own code: http://www.r-tag.com/Pages/CRDataSource.aspx
The free version works for one file without restrictions.

ssis excel source cannot acquire connection manager at DESIGN time

I have an SSIS (super)package that consists of several (about) 40 packages, each of which has several data flow tasks, most of them loading some excel data to a sqlserver database. So I have several excel source connection managers, one per excel file.
This has always worked fine until recently : I have to change an excel source in one of my packages (a column was added in the excel which has to be loaded in the destination sqlserver table) but I cannot edit the excel source in SSIS : when I click on "columns" I get an error box "DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER". So this is a design time issue, not a run time problem. I've seen a question like this one on stackoverflow but no answer. Anyone has an idea ?
I' ve already removed office 2007 and reinstalled office 2003 on my machine, but this didn't help
it has nothing to do with 64bit mode, which I've read about here
Is there some limit on the number of connection managers in ssis ?
Most of my connection managers were created with copy/paste and hence they have the same Id, although they point to different excel files. Could this be a problem ?
I should also mention that the package runs without any problems, so it's only "editing/changing" the package that doesn't work. For the moment I circumvent this problem by disabling the data flow that should change and by replacing it with a sql statement that hardcoded inserts the data from the excel into the destination table.
Maybe another intersting thing to mention : I can create a new package and add and change excel sources without problems, but then again, when I try to copy this excel source in my package, I cannot edit it.
Did you try to check the advanced options on the Source Connection?
Right click on the component and select "Show Advanced Editor..."
Select the column mappings tab and press the Refresh button.
This should point out that the XLS connection has some additional columns or that the file that you are pointing at, cannot be pre-validated at runtime.
M.
I'm not sure if this will work but try the Work Offline option in the SSIS menu in BIDS/VS. What this should do is not validate the connection before you edit the component. It might be able to get you into the component.

Resources