SSIS Excel Source connection and setting of package variable - ssis

Newbie to SSIS. I want to read an Excel spreadsheet, get a value, assign it to a package variable, and then use the variable in a SQL statement. I can read the excel and get the value, cannot figure out how to put the value into a variable (from the Excel source) so the SQL will run.

Easiest thing would probably be to have the excel source point to a RecordSet Destination. You can then Foreach-loop the object holding the recordset and extract the value(s) you want to work with that originated from Excel.

Related

Unable to use expression on excel connection manager in SSIS 2017

I'm trying to loop through excel files in a directory and perform a data flow task in SSIS.
The For-Each Loop container seems pretty simple to set up:
I map to a variable called FileNameTemp.
Inside the For-Each Loop, I have a data flow task where the source object is an Excel Source with an Excel Connection Manager. I use the FileName temp to set the File Name of the ExcelFileName:
My problem is whenever I try to run the package, I get the error below:
[Connection manager "Excel Connection Manager"] Error: SSIS Error Code
DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code:
0x80004005. An OLE DB record is available. Source: "Microsoft Access
Database Engine" Hresult: 0x80004005 Description: "Failure creating
file.".
I found other similar posts. I definitely have permission to write to this folder. If I remove the expression and just open the same file over and over it works. I also set DelayValidation to true on pretty much every level.
Try removing the "C:..." from your expression definition. The For-Each file enumerator will give the full path.
In the future you can set a breakpoint on your data flow task and view the value of your variable that you set in the locals tab.
Same answer, just more verbose than #mike Baron's answer is that in the ForEach Loop Container, the radio button is checked for "Fully Qualified" with the result pushed into our variable #[User::FileNameTemp]
Each file found in the specified source folder C:\SourceCode\ExcelSourceFinancialReconcilliation is in turn going to be assigned to that variable in the form of
C:\SourceCode\ExcelSourceFinancialReconcilliation\file1.txt
C:\SourceCode\ExcelSourceFinancialReconcilliation\file2.csv
C:\SourceCode\ExcelSourceFinancialReconcilliation\file2.xls
Then, when we set the Expression on the Excel Connection Managers ExcelFilePath property, we need to just use #[User::FileNameTemp] As it stands, the expression is doubling up the path so that Excel is attempting to find
C:\SourceCode\ExcelSourceFinancialReconcilliation\file1.txt\C:\SourceCode\ExcelSourceFinancialReconcilliation\file1.txt
As a general rule, only use a direct variable in the Expressions associated to "objects" in SSIS. Property1 = #Variable The reason for this, is that you cannot put a break point to on the evaluation to determine why #Property1 = "Foo" + #Variable is invalid. If you create a custom variable #Property1Variable = "Foo" + #Variable and then assign #Property1 = #Property1Variable, you can put a breakpoint in the package and then inspect the value of the SSIS variable. It's much easier to find problems this way.
Possibly helpful other answers on the subject
https://stackoverflow.com/a/18640174/181965
https://stackoverflow.com/a/21536893/181965

Trigger MS Access function with SAS

I’m a newbie on here so please be gentle :)
My question is: can I get SAS (9.4 with PC Files Server) to trigger a function in MS ACCESS that imports .txt files that SAS spat out earlier?
Background: I have inherited an Access database (.accdb, using vers. 2010), which source data comes from SAS. Current method is that SAS spits out .txt files, which I (semi-manually) import into the database. Semi-manually in that there is a button/macro that imports the files but I have to open the database and press the button. I would prefer not to have to intervene at all.
I tried to skip the import of tables by using PROC EXPORT (and PC FILES SERVER) and later PROC SQL (with Access database assigned via libname) to push the data from SAS directly. However, compared to the old approach, after doing a compact and repair, the database is still about twice the size. I searched the net on how to avoid increase in size but found no answers.
I would therefore like to keep the method of SAS spitting out the .txt files but also have SAS trigger the Access function in the database that imports the files.
The button in Access activates this code:
Private Sub ImportSASDataButton_Click()
Dim Update As Byte
Update = MsgBox("Have you ran the SAS program that creates the text files?" _
, vbYesNo, "Check files have been created")
If Update = vbYes Then ImportTables
Me.CloseFormButton.SetFocus
Me.ImportSASDataButton.Enabled = False
End Sub
Which if “YES” activates this code (which is the function I wish to trigger directly):
Function ImportTables()
Dim db As Database
Dim ITables As Recordset
Set db = CurrentDb
Set ITables = db.OpenRecordset("Tables", dbOpenDynaset)
Do Until ITables.EOF
Call ImportData(ITables![TableName], _
ITables![SpecificationName], _
ITables![FileName], _
ITables![DeleteExisting], _
ITables![Use])
ITables.MoveNext
Loop
ITables.Close
End Function
There are several SAS statements that can start external programs, including
%sysexec
call system
filename pipe
Access has the command line switch /x mymacro that will run a specific macro at startup, or you can create or update the AutoExec macro that is also run automatically every time Access is started.
So your SAS code might look like
%Spit;
%sysexec msaccess /x ImportTablesMacro;
#Richard shows you how to call Access from SAS. If you do not have the ability to run command lines from your SAS session (some system administrators disable this), you can write a shell script.
First call SAS to create the .txt files.
Then call Access with the method Richard describes to run the macro.

After splitting database importing excel files gives error 2950

Before splitting my database I was using a macro for importing excel file to my table and it was okey.
Now after splitting database when I use that macro from front-end I got error:
You cannot record your changes because a value you entered violates the
settings defined for this table or list (for example, a value is less than
the minimum or greater than the maximum). Correct the error and try again."
The error number on the Macro Single Step pop-up is 2950.
when i use macro from back-end it does not have problem and works.
please help because i need importing from front-end.
equivalent VBA code for macro i have used is like below, it works from back-end and gives error from the front-end:
DoCmd.TransferSpreadsheet acImport, 8, "Rep_Indicator", "E:\Rep_Indicator", True, ""

Reading excel rows from Execute sql task SSIS

Is it possible to read all rows from Excel sheet through Execute SQL Task from SSIS and reading each value in for loop container ?
You probably could and save the output to a variable, which you can use in the loop container. There may be a gotcha with permissions and/or linked server setup.
Here's another approach:
Create Data Flow
Create Data Connection to Excel file
Create Excel file source transformaion
Use Recordset Destination to populate a variable
Use the variable in your loop, setting Enumerator property to Foreach ADO Enumerator

ExcelConnection manager dynamic file path in SSIS

When i tried to give connection string in the form of a variable to "Excel Connection Manager", it gives me the below error.
the connection string format is not valid. it must consist of one or more components of the form x=y seperated by semicolons. This error occurs when a connection string with zero components is set on database connection manager.
Since you want a dynamic file path, when you are setting up the Expression for the Excel Connection Manager, you are probably selecting ConnectionString as a property in the Property Expressions Editor. This results in the error you specified in your question.
What you actually need to select is the ExcelFilePath property. Add your variable in the Expression field afterwards as you would normally do.
You should give us more information. What's the value of you variable when the error pops up? To exactly what property have you assigned this variable?
Anyway, I suspect that you didn't set [Delay validation] property of your connection manager to True - without it ssis check if you connection manager is ok, before you even assign value to the variable (which is dynamic and happens during execution in some loop, I suppose).