ExcelConnection manager dynamic file path in SSIS - 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).

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

MS Access Vb How to build a text string to reference a dynamic column in and Vb SQL query and then execute that text string using the Eval function

In the following example where POOPTrst is a a DAO recordset (systems object) referencing the Vb SQL query or statement.  this code returns "Run-time error 2482" and/or "Microsoft Access cannot find the name 'POOPTrst' you entered in the expression"  (note:  the POOPTVal variable holds a date).
POOPTWkDmd = Eval("POOPTrst" & "!" & POOPTVal)
In the following example where POOPTrst is a a DAO recordset referencing the Vb SQL query.  this code returns "Run-time error 3256" and/or "Item not found in this collection"  (note: with or without parenthesis around the variable POOPTVal)
POOPTWkDmd(POOPTCounterInt) = POOPTrst!Eval(POOPTVal)
If I remove the Eval function and the POOPT date variable and type literal characters into the code I get the proper/expected return value and/or response (note:  the problem is that 1/5/2009 is a dynamic value that is calculated at run time
POOPTWkDmd(POOPTCounterInt) = POOPTrst![1/5/2009]   
Use this syntax: rs("Fieldname") instead of rs!Fieldname
POOPTVal = "1/5/2009"
POOPTWkDmd = POOPTrst(POOPTVal)
for more explanation see this answer: https://stackoverflow.com/a/34969410/3820271
One issue is that Eval() doesn't know anything about VBA variables or objects such as recordsets. If you want to use those, build a string containing their values and give Eval() that string.
However, I'm not sure Eval() is what you should use here. It seems you want to reference the value of a field in your POOPTrst recordset, with a variable to hold that field name. If that is correct, use the variable with the recordset's Fields collection: POOPTrst.Fields(POOPTVal).Value

SSIS Setting the HasSideEffects property

I am calling a stored procedure in a data flow task that outputs a value that is not being used. Because its not being used the optimizer removes the component during runtime. It states I can override this by setting the 'HasSideEffects' property to true but I don't see where to set this. I see it in the 'Input and Ouput Properties' of the OLE DB Source but its read only.
Turns out that I had set the 'RunInOptimizedMode' property to true and that was causing the issues. Set it to false and I am good to go

Error during Closing the MS Access application

When i am closing the MS access application (application.mde) i am getting a error and looks like database has been refreshed and gettting a some other records.
Error Messaage : The Expression on unload you entered as the event property setting produced error:datatype mismatch in criteria expression.
Kindly help me on it.
the OnFormat property of the form /controls might be set to something other than the string "[Event Procedure]", or may not be named as a valid macro.

Seemingly getting wrong connection string from tabledef

Using Ms Access ...
I am trying to change the user to which I am connected to a SQL Server Database from Access. The startup form from my Access Application dynamically connects to the tables via an Altered version of a routine posted on Microsoft's KB. In Essence it deletes the tabledef that matches the name localName you call it with, Calls Currentdb.CreateTableDef to create a new one with the appropriate new connection string and appends it the the CurrentDb.TableDefs collection. As far as I can see, its the append function that actually contacts the database and throws an error if your connection string is wrong.
In my case, I did an original pass through all the tables in my database calling this routine with an old (standardised - ie I normally use this) string and all tables connect fine.
I am now trying a second pass through this start up form with a new user/password combination so as to test different permissions in the database.
I have then built a new connection string with a revised name and password and am currently single stepping through the function I just described.
I have a variable td which contains the newly created tabledef and I am just prior to appending it to the Currentdb.TableDefs collection
In the debugger "Immediate" window ?td.connect gives the connection string with the newly formed connection string correctly and ?td.name gives tblConfig as the table name.
Just to ensure the TableDef has been correctly deleted from the current collection I did ?CurrentDb.Tabledefs("tblConfig").Connect from the immediate window and was rewarded with a dialog box that said the collection didn't contain a member with that name
I then single step over the line
CurrentDb.TableDefs.Append td
And now call ?CurrentDb.Tabledefs("tblConfig").Connect again from the debuggers Immediate window and the response is the old connection string not the new one.
There is an OnError active in this routine, but It is not activated during the single stepping.
The only explanation I can think of for this, is that somehow the old connection string is stored on disk as a result of saving the database at some point and append doesn't copy across the connectionstring when it is finally appended.
Does anyone have a better explanation?
It turns out that the connection string is indeed cached
http://blogs.office.com/b/microsoft-access/archive/2011/04/08/power-tip-improve-the-security-of-database-connections.aspx
I had an incorrect password for the new connection string (one character was wrong) and it appears that access does not store the new username and password when that problem happens.
Somehow, despite deleting the old tabledef with the old username and password, Access was able to get it back - maybe it was cached, I don't know - and use it. Obviously that worked and so it carried on with that string rather than the new one.
It seems that because the old string worked, it didn't bother to throw an error, so I was now connected to the table with a server login that didn't have the same permissions as I expected.