Please Help! Dynamic DB Connection In Foreach Loop
Apr 4, 2006
Hello-
I'm trying to read a table that has database connection information for other DBs and use this within an "Execute SL Task" task. I have seen a number of posts that talk about this possibility, but I have not been able to get it to work yet.
When I've tried to set the connection to a variable (@[User::DB_ConnectionStr]) in the Expressions area of the SQL Task, the Connection type defaults to OLE DB and I can't seem to force it back to ADO or ADO.net.
I've tried doing this with the variable being set to both a connection object and a String with the connection string, but neither seems to work.
Any suggestions? Should this be a string value of the connection string? Am I missing something when trying to set the connection type?
Thanks much!
Tristan
View 3 Replies
ADVERTISEMENT
Nov 29, 2006
Hi,
I'm trying to write a package that imports a bunch of Excel files into a sql server table. My import routine works fine when I do not use a foreach loop container. I then add a Foreach Loop Container with a Foreach File Enumerator and create a variable to store all of the excel file names to use with my excel connection manager in the connection string property.
When I run the debugger I get the following error:
TITLE: Package Validation Error
------------------------------
Package Validation Error
------------------------------
ADDITIONAL INFORMATION:
Error at Import New Data [My Data (Excel) [4234]]: The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009.
Error at Import New Data [DTS.Pipeline]: component "My Data (Excel)" (4234) failed validation and returned error code 0xC020801C.
Error at Import New Data [DTS.Pipeline]: One or more component failed validation.
Error at Import New Data: There were errors during task validation.
Error at ImportMyData [Connection manager "Excel Connection Manager"]: An OLE DB error has occurred. Error code: 0x80040E4D.
(Microsoft.DataTransformationServices.VsIntegration)
I've read the varous posts on this forum and others with people having this problem and nothing that was recommended to them works for me. I've also read the Msdn article 'How to:Loop through Excel files and Tables' and followed the directions there without success. I've tried the following with no success:
I've tried to create first a hard coded connection string in the excel conn. manager which works but as soon as I set the experessions: connection string property = my file enumerator variable it breaks.
Turned the Delay Validation to True for the package as well as the task
Set the Connection string equal to not just the variable coming from the file enumerator but to the full connection string : "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @[User::excel_filename] + ";Extended Properties="Excel 8.0;HDR=YES";"
I've also tried to set the excel filepath property instead of the connection string and this didn't work either.
I'm getting really frustrated. Any advice on why something so simple doesn't work for me would be appreciated.
Thanks
Anya
View 3 Replies
View Related
Sep 28, 2006
How can I use a foreach loop container with an Excel connection manager. It is virtually impossible to configure the ConectionString property through expressions builder. Everything works fine with a Flat File connection manager but when it comes to Excel, I get the following error message: Error 1 Validation error. Extract Four: Extract Four [1]: The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009. Tarification.dtsx 0 0
Please ! Heeeelp ! tel me how I can loop through Excel files !
View 16 Replies
View Related
May 25, 2007
Purpose: Need to import excel source data into SQL Server 2005 tables. Excel source data comes in nulitple excel files with the same structure but different data. I would appreciate someone taking a look at the following information and notifying me of what I am doing incorrectly.
I Inserted a foreach loop container, a data flow task located inside the foreach loop contaiiner, an excel and SQL Server 2005 connections.
After trying multiple times I went the following URL and followed step by step direction on how to connect excel workbooks dynamically: http://msdn2.microsoft.com/en-us/library/ms345182.aspx . I also used http://www.sqlstrings.com/ as a reference when creating the connection string.
Creating a Foreach Loop Container:
1. Opened foreach loop container 2.Set the Enumerator to 'Foreach File Enumerator" and configured the enumerator by setting the directory location and file base name to E:ClientsDep CommBEABEA_Test_Source and *PersonnelExpense*.xls respectively. 3. Clicked Variable Mapping; created two variables called, "ExcelFile", and "ExtProperties" and closed out of the foreach loop container.
I. Created Excel Connection:
Created excel connection called, €œDynamic Excel Connection Manager,€? that initially pointed to one of the excel workbooks.
Went to the connection properties by right clicking the connection manager.
Expanded Expressions and clicked the ellipsis button to bring up property expressions
Chose Connection String in the Property.
Clicked the Expression Ellipsis button.
Put the following inside the Expression multi line text box:
A. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @[User::ExcelFile] + ";Extended Properties="" + @[User::ExtProperties] + """
Clicked the Evaluate Expression button to get the following:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=;Extended Properties=""
Clicked Ok button
Inserted a Data flow task inside the foreach loop container.
II. Configured Tasks that is associated with Dynamic Excel Connection Manager or Package:
Set the Foreach loop container Delay Validation to true.
Set the Data Flow Task Container Delay Validation to true.
Set the Dynamic Excel Connection Manager Delay Validation to true.
Set the SQL Server Connection Manager Delay Validation to true.
Set the Package Delay Validation to true.
Package Locale ID set to English
Ran the package after connecting the excel source data flow to the OLEDB destination and have inserted part of the error in this post. Please see below.
Error: 0xC0202009 at Package, Connection manager "Dynamic Excel Connection Manager": An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft JET Database Engine" Hresult: 0x80004005 Description: "Could not find installable ISAM.".
I modified the connection string after receiving the error by removing the extended properties. The following is the modified connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @[User::ExcelFile]
I repeated step I.6 above and received the following expression: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
I ran the package and received the following error in part: OLE DB record is available. Source: "Microsoft JET Database Engine" Hresult: 0x80004005 Description: "Unrecognized database format 'E:ClientsDep CommBEABEA_Test_SourcePersonnelExpense_OCCs_051007.xls'."
I did not find anything helpful when I searched for the above errors and would very much appreciate anyone€™s assistance on this issue as this issue needs to be taken care of ASAP.
Does anyone have any ideas as to why I received this error and what can I do to resolve this issue?
Your assistance in this matter is truly appreicated!
Thanks!!
Lee
View 7 Replies
View Related
Jan 11, 2007
Hello, I am getting very frustrated! I have got a Foreach loop container which I am processing files within a folder. I have a flatfile connection manager which I have set up using a test file and have updated the expressions attribute to be the package variable I set up in the collection for the loop container however everytime I run it I get the error: 0xC0202094 cannot retrieve the column information from the flatfile connection manager. I can only guess that it is either the variable being passed to the connection manager or the way I set up the connection manager. When I msgbox the variable in a script component before the dataflow step, the variable for the file seems fine. Any suggestions are REALLY appreciated.
Yours
Jayne
View 2 Replies
View Related
Jan 18, 2007
Hi ALL,
Getting Access Denied To FileName Error When Using the Execute Sql Task (With File Connection) into a Foreach Loop Container.
Please Note :
I have a folder containing .sql files. I have to dynamically loop through the files and send them as a File connection Folder to the Execute Sql Task.
When I run this Package I am getting the follwoing error :
[Execute SQL Task] Error: An error occurred with the following error message: "Access to the path 'C:ProjectsFuzzy Lookup DataFlow ExampleScripts' is denied.".
Also I have logged in to the machine as Administrator and to Sql Server with sa.
Please help.
Thanks.
Regards,
Salil
View 1 Replies
View Related
Apr 4, 2007
How do you sort files from the Foreach loop container?
I love this component, except I can't get it to sort by filename.
Nice to know how to sort by timestamps also.
Dave
View 27 Replies
View Related
Apr 22, 2008
Hello
I have a question
How is foreach loop container - foreach ADO enumerator performace in SSIS package compares to use of cursors in stored procedures
Is there any articles comparing them
I understand a lot of factors can affect the performance, however what is expected performance for the foreach ADO enumerator loop for large dataset. What is Microsoft recommendation for that - recommended - not recommended (using large datasets - over million records)
Thank you
Arminr Bell
View 4 Replies
View Related
Apr 11, 2007
Hi,
I have no "Foreach File Enumerator" oprtion in the Enumerator Property of the Foreach Loop Component.
I have this enumerator in the c:Program FilesMicrosoft SQL Server90DTSForEachEnumerators folder.
Also I check it in the GAC - it does not here. I try to execute gacutil.exe -iF ForEachFileEnumerator.dll, but it is failed with "Failure adding assembly to the cache: The module was expected to contain an assembly manifest." Seems it is not managed enumerator.
Please help me.
Also information on how to regeister unmanaged enumerators are welcome!
View 3 Replies
View Related
May 28, 2010
difference between FOR LOOP and FOREACH LOOP with example(if possible) in SSIS.
View 4 Replies
View Related
Mar 3, 2006
I have a foreach loop that is supposed to loop through a recordset, however it doesn't loop. It just repeats the same row, row after row.
I would like to look into the recordset variable but I can't because it is a COM object and the ADODB namespace is not available in the script task.
Any solution to this? anyone experienced anything similar
View 1 Replies
View Related
Jul 10, 2006
I need to execute about dozen packages from another package... how do I dynamically pass the dozen package names to the package and execute using foreach loop...?
idea is to store the names of packages in a text file and set the file connection property reading each package names from the text file... in this way I can just configure/edit the text file from time to time, the packages and the units that I want to execute...
Someone please provide me steps to make it work.
Thanks in adv.
View 4 Replies
View Related
Jun 10, 2007
Hi,
I'm looping through some query data and doing a Script Task check inside the loop on a datetime field.
If the datetime happens before 10 o'clock:
- Store the data row in Table1
If the datetime happens after 10 o'clock:
- Store the data row in Table2
How can I store the datarow inside the loop without inserting it into a database table?
I need to access the data in the next step after the loop. How can I do this?
Thank you very much!
View 4 Replies
View Related
Feb 28, 2008
The foreach loop below runs fine and it sends emails as expected but the SP does not update the Companies table. Any thoughts? How do I cause the SP to execute?
PROCEDURE newdawn.EmailSentDate @CID intAS UPDATE Companies SET Companies.LastEmailDate = (GetDate()) WHERE tblCompanies.C_ID = @CID RETURN
foreach (GridViewRow row in GridView3.Rows) { pstrTo = row.Cells[2].Text; CEmail = row.Cells[2].Text; CName = row.Cells[3].Text; CID = row.Cells[1].Text; CState = TextBox1.Text; CCity = row.Cells[5].Text; CCat = row.Cells[4].Text; CCID = row.Cells[0].Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString); SqlCommand cmd = new SqlCommand("EmailSentDate", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CID", CCID); try { System.String mailServerName = "mail.domain.com";
REST of code sends email to email address found in each row ....it all works find but SP above does not fire.
View 12 Replies
View Related
Jan 22, 2008
Hello Experts,
Sorry that I open a new thread again but I didn€™t found any good tutorials about foreach loop container. I would like to read every row from one table and do something.
I red something about sql task€¦ Can someone give a little instruction, please?
Kind regards,
Alex
View 3 Replies
View Related
Feb 15, 2007
Hi
I using data flow task to import from flat file to database but i need to use Foreach Loop Container to import multiple files in specific folder and all will be insert in the same table
tahnks & Regards
View 1 Replies
View Related
Feb 27, 2008
Help with Looping in a SSIS Package
Scenario:
We have a web app that lets our existing clients insert new locations into a table (Clients) in a SQL Server DB. This table has an Identity column as the PK. This table also has another ID field HBID that is the PK for another table (HLocation) in another Database system (Sybase). The HBID field is given a Default value of €˜1€™ during an insert operation in our (SQL Server) table, Clients. The Sybase database uses a Sequence table for inserting a PK into the table. Whenever our clients insert a new record in Clients (SQL Server), I need to generate a new HBID from the Sequence table in (Sybase), update the HBID in the Clients table (SQL Server) and then finally insert the record with the new HBID into table HLocation (Sybase).
I have devised a SSIS package for this as following: Note all variables are scoped at the Package Level.
Execute SQL Task #1 that drives a For Each Loop with the following properties:
General:
Connection Type: OLE DB
Connection: SQL Server DB
SQL SourceType: Direct Input
SQLStatement:
SELECT COID, HBID, Name, DateCreated
FROM Client
WHERE HBID = '1'
ResultSet: = Full Resultset
Result Set:
Result Name = 0
VariableName = USER::rsClient Variable Type = Object
ForEachLoop with the follwing properties:
Collection:
Foreach ADO Enumerator
ADO Object Source Variable = USER::rsClient
Enumeration Mode = Rows in first table
Variable Mappings:
Variable: Index:
COID 0
HBID 1
Name 2
DateCreated 3
Inside of the ForEachLoop I have another Execute SQL Task to generate a new HBID from Sybase set up as following.
Execute SQL Task #2
Connection Type: OLE DB
Connection: Sybase
SQL SourceType: Direct Input
SQLStatement:
UPDATE Autoinc SET INC_LAST = (INC_LAST+1) WHERE INC_KEY ='HBID';
SELECT INC_LAST AS NewHBID FROM Autoinc WHERE INC_KEY ='HBID'
ResultSet = SingleRow
Result Set:
Result Name = NewHBID
VariableName = USER::NewHBID, VariableType = Int32
Also Inside the ForEachLoop is a Script Task that has all of my variables as ReadWrite = COID, HBID, Name, DateCreated and NewHBID. I concatenate the values in a string a pass the string into a Message Box to make sure they are looping correctly and they are.For example the results might look like the following:
12698, 1, John Doe Trucking, 10/1/2007, 14550
13974, 1, Joe Smith Trucking, 10/1/2007, 14551
10542, 1, Dave Jones Trucking, 10/1/2007, 14552
Etc.
The values 14550 -14552 are the new HBID being generated in the loop.
The problem is that when I try to Update the HBID in the Client table (SQL Server) with another Execute SQL Task I keep getting the same NewHBID number.
In this case 14550 would be updated for every record instead of the next number in the loop.
I have set up Execute SQL Task #3 as follows:
General:
Connection Type: OLE DB
Connection: SQL Server DB
SQL SourceType: Direct Input
SQLStatement:
UPDATE Client
SET HBID = ?
WHERE HBID = '1'(SELECT COID, HBID, Name, DateCreated FROM Client)
ResultSet: = Full ResultSet
Result Set:
Result Name = 0
VariableName = USER::rsNewClient, VariableType = Object
Parameter Mapping:
VariableName USER::NewHBID, Direction = INPUT, DataType = Long
ParameterName = 0
I€™ve tried putting Execute SQL Task #3 inside of the ForEachLoop, connecting it to the output of the ForEachLoop. I€™ve tried setting up a dataflow with a Derived Column using the USER::NewHBID as the Expression.
I still get the same results, 14550 added to every row.
Can any one help or shed some light?
Any and all suggestion will be deeply appreciated!
Thanks !!!
View 1 Replies
View Related
Jun 14, 2007
Hi,
Let's say you have a Data Flow Task that connects to a Foreach Loop, looping through the data.
Somewhere inside the Foreach Loop, you set an int variable MyInt to a value.
My question:
Is it possable when each iteration begins to set MyInt to 0?
Thanks in advance.
View 4 Replies
View Related
Feb 28, 2007
I'm having a problem where I'm using a Execute SQL Task to retrieve a dataset and storing that in an object variable. Then on success of that execute sql task I use a foreach loop task to go through the dataset and do 2 tasks inside the foreach loop. When I execute this package I have ~12 records in the dataset however when I get to the foreach loop in the 2nd iteration it keeps repeating it. It acts like it is stuck on the second record (tuple) and never goes on. I'm using an ForEach ADO Enumerator in the foreach. I've even set a breakpoint on each iteration and no task fails in side the foreach loop. I'm completely perplexed why it will iterate to the 2nd record but get stuck there in an endless loop. I've tried this on 2 different computers (with different data values) and the same thing happens. Does anyone have any suggestions?
View 40 Replies
View Related
Oct 10, 2006
I defined Foreach File Enumerator,there are more than 2 files needed to deal with,it donesn't work if i don't specify filename in flat file connection manager editor,however if i specify filename then doesn't foreach files
what should i do? thanks
View 4 Replies
View Related
Oct 9, 2006
Help,
Trying to through a process together and using the "ForEach Loop" task. When configuring the task and using the ForEach Loop Editor I do not have the "ForEach File Enumerator" in the drop down. Anyone know whats going on or what I need to do to make this appear. I only see 5 selections: ADO, ADO.Net Schema Rowset, Variable, NodeList, and SMO Enumerators. I am also using the SQL 2005 eval with SP1.
Thanks,
John
View 2 Replies
View Related
Jan 3, 2007
Here is what I am attempting to get accomplished. I have an SSIS package that contains a Foreach loop container. This container executes a number of SQL tasks in order: SQL Task 1, SQL Task 2, SQL Task 3.
if the SQL task 1 succeeds it should flow on to SQL Task 2 and 3. This works fine when the SQL tasks do not fail...
In the event of any SQL Task failing control should flow to a send mail task to alert about the failure. Next the Foreach loop container should go to the next enumeration in the Foreach loop container and start the next new SQL task 1. So far I have been able to get the control to flow to the send mail task when a SQL Task fails. What does not work is when one SQL Task fails the entire Foreach loop fails and does not move to the next enumeration. It should only fail the package and move on.
Any help would be appreciated....
View 5 Replies
View Related
Feb 6, 2008
if there are no files in the directory i'm searching? Or if not fail, give me something so that I know & can raise a flag as needed?
thanks
View 1 Replies
View Related
May 9, 2006
I need to put a FTP task inside a Foreach Loop Container to upload data files to many different FTP servers. The container holds a variable with object data type that includes necessory FTP info (FTP server address, login, password and remote path). How do I configure FTP task so that I can pass the variables to it?
Thanks,
Jia
View 1 Replies
View Related
Feb 11, 2006
All,
I€™m new to SSIS and have a question about foreach loop container.
Basically, I have 4 data flows and each of them has a variable that need be pass on to the next step, each of the variables will call a same stored procedure.
What should I use here? I guess I can use foreach loop container with the stored procedure inside of it, is that right? I tried all day yesterday and cannot make it work.
The foreach loop container did not call the procedure at all. Could someone kindly tell me how to do it?
View 4 Replies
View Related
Mar 22, 2006
We discovered that the Foreach loop isn't recalculating the number of files found upon each new loop iteration, so if any new files are placed into the receive directory during the looping, they are not detected/processed. is this a bug or product intention?
View 3 Replies
View Related
Mar 30, 2007
Hi
Can anyone point me to an example of using a ForEach Loop Container to step through the rows in a recordset. I cannot seem to see how this is done from the help files.
Thanks
View 6 Replies
View Related
Jun 8, 2006
I have a foreach loop that is processing files in a directory. One of the tasks is the execute sql task that calls a stored proc. If this stored proc returns a certain value then I need to exit the loop and not process any more files. But I have been unable to figure out how to make this happen.
Any help would be greatly appreciated.
Thanks!
GN
View 5 Replies
View Related
May 26, 2006
I would like your help with the Foreach loop container. Boy, am I having issues with using it for looping through an ADO.NET dataset or what!?!? My control flow has a data flow task that is executing a Data Reader task (creating a .NET dataset for me). Now I go back to the control flow and add a Foreach loop container to loop through each record in my dataset. But which type of the Foreach loop container should I be using? I see an option to use Foreach ADO.NET schema enumerator but not sure how to configure it. Also I used the Foreach ADO option, but setting up variables to go through every column is an absolute pain in the you know what!!?!! I have about 200 columns and I want an easier way to refer to those columns in my transformation phase.
Hope you are able to help me out here.
View 1 Replies
View Related
Jul 13, 2006
Does anyone have a need for an AMO Enumerator in the ForEach loop as well as an SMO Enumerator? I think this would be a fantastic addition to SSIS.
If you agree, vote for it here: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=163202 and LEAVE A COMMENT!!!!
-Jamie
[Microsoft follow-up]
View 3 Replies
View Related
May 3, 2007
Hi,
I'm attempting to use the Foreach loop container to loop through the excel files located on a shared network folder. I've set up the Excel file connection manager to include the user variable generated from the container, but I get the below error messages when applying that variable to the connection string in the data flow. I've tried everything but I can't seem to get SSIS to recognize the path of the Excel files. I've tried copying the files to my PC, I tried running the package on the server, etc. The connection works fine if I set it up to point to any of the excel files in the network directory, but not with the Foreach loop connection name.
Any help or suggestions would be greatly appreciated! I've looked everywhere and tried everything but to no avail...
Thanks,
Kevin
TITLE: Microsoft Visual Studio
------------------------------
Error at GDW - RDB LOAD [Connection manager "UK RDB"]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E4D.
Error at Extract UK RDB [UK RDB [1]]: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "UK RDB" failed with error code 0xC0202009. There may be error messages posted before this with more information on why the AcquireConnection method call failed.
------------------------------
ADDITIONAL INFORMATION:
Exception from HRESULT: 0xC020801C (Microsoft.SqlServer.DTSPipelineWrap)
------------------------------
BUTTONS:
OK
------------------------------
View 9 Replies
View Related
Nov 6, 2006
Hi
Currently the ForEach Loop container is set to loop over the entire collection of records in my table, but I only need to loop thru the records where the status = x. How is that possible? Can I use expressions to set the enumerator to do something like this. Basiclly the collection values are used for further processing, and I would like to avoid looping thru records which have been processed already, which means they already have a status set to y. Please let me know. Thanks.
MA
View 6 Replies
View Related
Oct 8, 2007
Hi
I am trying to write an SSIS package that will look though all the databases on a server (in this case 2k server) and get the list of tables in each database
I have created a Execute SQL Task with select name from master..sysdatabases where name <> 'Tempdb'
This is connected to a Foreach Loop that uses Foreach ADO Enumerator on the first table from the var generated in step 1 (List of databases)
Within the Foreach loop there is a dataflow that has a a sql command
select @@servername SQLInstanceName
,db_name() DatabaseName
, name TableName
--, getdate() RecordDate
from sysobjects where type = 'u'
This should return all the tables in a database however the databases is not changing it just lists all the tables in the master database times the number of databases on the server
Can anyone point me in the correct direction for this one
Thanks
Kevin
View 1 Replies
View Related