Need advice on SSIS solution with variable based connection managers - sql-server

I am working on the SSIS solution to get 20 different txt files from a specific folder and upload them to different SQL Server database tables. I added a mapping table with table_name, file_name, file_path, full_connection_string. How do I tell connection manager which connection to use for a certain file?
Which variables/parameters to use and where?
I do not want to have 20 txt connections(for the known filename difference) and 20 database connections.
All online tutorials are old and don't match Visual Studio 2019 UI.
Any help is highly appreciated!

You can have parametric connection string.
Define the variable: _Server (string)
Select the Connection
In Properties window, select [Expression]
Use your variable for (SereverName)
Obviously you have a loop and you can load the proper server name into your variable so in each iteration, the connection will be connected to specific server.

You will need one database connection manager for each target database as this is scoped at the database level.
You will need a flat file connection manager for each unique file metadata. You can have twenty Sales-date.txt files that use a single flat file connection manager and then expressions will take care of consuming the different files.
However, if you have Sales.txt and Customers.txt, the metadata, aka the columns inside the file, are going to be different and that's fine but you'll have to create a flat file connection manager for each of those types. This is the contract you're making with the SSIS engine - I promise all of the files this FFCM will touch conform to this standard. You will also need to have a Data Flow Task for each of these FFCMs as the engine computes how many rows of data it can operate on at a time based on the type and column constraints in the source.
If it were me, I'd spend a few days looking at Biml. Biml is the Business Intelligence Markup Language and what it allows you to do is describe your problem in a repeatable way. i.e. For each of these file types, I need an SSIS package that is a for each file enumerator to pick up the current file. Inside that, a data flow task to ingest the file. Then a File System Task to archive the file out of the working folder.
You've already started down this path identifying your metadata ( table_name, file_name, file_path, full_connection_string) the only thing remaining is to describe the contents of your files. If you look through my SO answers, you'll find plenty of answers that use Biml to create a reproducible solution.

Related

Find source and destination tables across all packages in a solution?

I have around 10 solutions .sln, each of them with multiple packages in it.
I would like to be able to get:
solution name
package name
mapping between the source and target columns
source and target table(s)
source connection or source DB
Would that be possible by parsing the .dtsx file? I understand I can save it to an .xml file.
For now, what I did was to configure the SQL Server Profiler and to run all packages to retrieve the current SQL queries, dumping them in a table and parsing them directly in SQL Server.
I wonder if there is not a better solution using an external tool (like biml) or by parsing the files directly.
Any suggestions are appreciated

SSIS: How to Load differently named flat files from a folder using SSIS

I'm very new to SSIS packages so please forgive me if this is a simple query.
I have 2 SSIS packages that have been set up;
The first picks up a csv file, formats the data slightly (cuts off a prefix in one of the columns) and places it in another folder with an updated filename and timestamp.
The Second package imports the formatted file into a SQL database table.
The issue that I have is that the incoming file names for the first package may differ, the structure of the data will remain the same.
Is there a way to configure the flatfile connection manager to pickup any files in the C:Incoming\ folder?
Thanks in advance.
You can use a foreach loop container, to get the files in a folder, and use expressions in flat file connection to get it.
For a detailed answer, you can refer to this article:
Loop through Flat Files in SQL Server Integration Services

What is the best way of loading different csv files into different SQL Server tables using SSIS?

Should I reuse the same Flat File Connection Manager or I should place individual Flat File Connection Manager for each files to be imported?
Description:
I have 30 CSV files with different structure and I need to import these files into the SQL Server database.
Currently I am using separate Flat File Connection Manager for each Flat File Source. Then pushing the data into the SQL Server database using OLEDB Destination.
Should I reuse the same Flat File Connection Manager?
Can you guide me - how to do this? Any links will be helpful.
Because the structure differs between your files you should use separate connections. This allows you to properly define the column names, sizes and data types for each file type.
Instead of creating 30 Flat File Connections just use one inside a Foreach Loop container passing in an Expression for the file name.
To solve the problem of your CSV files being in different formats, when you create the Flat File Connection select Ragged right instead of delimited, this will treat each row in file as one very wide column instead of multiple fields (make sure you make the column wide enough to handle your files).
You can then send the output of your Flat File Source into a Script Component, in to which you can put all the logic to handle your files. Use a Regex or a split to convert each row back into fields and then you have the full power of C# to process each row. A Script Component can also have multiple outputs so you can even use it like a Conditional Split.
This might seem like a bit more work (depends or what your files are like and how you are processing them), but then end result is less moving parts.
I think you can use MultiFaltFile as Source connection Manager. Using this you can select multiple files at a time.
See the link below:
http://www.sqlservergeeks.com/sql-server-import-multiple-files-in-ssis-using-multi-flat-file

Automated file import with SSIS package

I am very new to SSIS and its capabilities. I am busy building a new project that will upload files to a database. The problem I am facing is that files and tables differentiate from one another.
So what was done is I created a table that will map each file's columns to the specific table's column the data needs to be stored in, in a separate table. I want the user to manage this part when they receive a new file or the file layout changes some how.
As far as I know about SSIS is that you can map each file to a table and it can be scheduled as task.
My question is will SSIS be able to handle this or should I handle this process in code?
Many thanks in advance
I would say it all depends on the amount of data that would be imported into your SQL server, for large data sets (Normally 10000+ Rows) it becomes a necessity to utilize the SSIS as you would receive performance gains in your application. Here is a simple example of creating a SSIS package using code. For smaller data operations I would suggest using a combination of this and this. Or to Create a dynamic table on your SQL server based on the file format, look at this
SSIS can be very picky about file formats, so if the files are completely different, then it probably isnt the tool for the job. For flat files, SSIS requires the ordering of columns to be the same.
If you know that your files will only ever arrive in one of 5 formats (for example), it wouldn't be much trouble to write 5 packages to import them. If any new file could have a totally different schema, I dont think SSIS would be the right tool for the job.

Loading many flatfiles into SQL Server 2005

I have a very annoying task. I have to load >100 CSV-files from a folder to SQL Server database. The files have column names in first row. Data type can be varchar for all columns. The table names in database can just be filename of the CSVs. What I am currently doing is that I use Import/Export Wizard from SSMS, I choose flatfile from dropdown box, choose the file, next->next->next and finish! Any ideas how can I automate such a task in Integration services or with any other practical method?
Note: Files are on my local PC, DB-server is somewhere else, so I cannot use BULK INSERT.
You can use SSIS - Foeach loop container to extract file names - by arranging to particular format.Use a variable to dynamically fill the variable with file name.Then in dataflowtask , use flat file source for source - oledb destination.
Please post some sample file names.so that i can learn and guide you properly.
Thanks
Achudharam

Resources