142 How to move files and append current date to the file in SSIS

  Рет қаралды 2,708

Learn SSIS

Learn SSIS

Күн бұрын

Пікірлер: 13
@dbin805
@dbin805 5 ай бұрын
thank you for putting this together. nice job.
@vak7553
@vak7553 Жыл бұрын
I have an issue with the flat file connection manager as I’m giving sample file name , so when I execute the package the file move to dest folder , next time when I run the package it fails as the file used in the connection manager is missing in the source folder it’s moved to dest folder , please advise. I get the error the system cannot find the file specified
@learnssis
@learnssis Жыл бұрын
here I can think of 2 solutions 1. use the foreach loop container and inside the foreach loop container put the data flow task that imports the file, this way data flow task will only get executed if there is a file in the folder. 2. use script task to check if a file exists or not, if file exists then set the value to a bool variable like IsFileExists = true. And then before loading the data using data flow task, on precedence constraints check if IsFileExists==true then execute data flow task. kzbin.info/www/bejne/eHrRdIWard6tgpI
@vak7553
@vak7553 Жыл бұрын
@@learnssis in the flat file connect manager properties I used the expression as connectionstring and pointed to filepath variable. No more error then with dynamic configuration of the flat file connection
@BrundaG-n1f
@BrundaG-n1f Жыл бұрын
I have load the excel data to sql using ssis ,data should load in consecutive manner like 1st dec 1st file should be loaded and nect dec2nd file should be loaded. Can you help with this
@learnssis
@learnssis Жыл бұрын
Take a look at this video, I have shown how to load the files in an order kzbin.info/www/bejne/qKW8mqWVZ7ifhq8
@BrundaG-n1f
@BrundaG-n1f Жыл бұрын
It is based on date modified but I want to load using dates in filename
@learnssis
@learnssis Жыл бұрын
@@BrundaG-n1fIt is an interesting topic, maybe I will make a video on this one. How I will do this is that 1. I will create a sql server table to hold the file information create table fileInfo(Id int identity, FilePath varchar(1000), FileDate date) 2. Now I will write some C# code to insert the data into sql server table with file name and date part of the file name. This is my code. string currentdatetime = DateTime.Now.ToString("yyyyMMddHHmmss"); string LogFolder = @"D:\Files\Logs\"; try { string[] files = Directory.GetFiles(@"D:\Files", "*.CSV", SearchOption.TopDirectoryOnly); string connectionstring = @"server = DESKTOP-EKJ1P64\SQL2019; database = Training; Integrated Security=SSPI;"; SqlConnection sqlConnection = new SqlConnection(); string sqlquery = ""; sqlConnection.ConnectionString = connectionstring; sqlConnection.Open(); foreach (string file in files) { //Emails_20230105.CSV string str = Path.GetFileNameWithoutExtension(file); str = str.Substring(str.Length - 8); DateTime dt = DateTime.ParseExact(str, "yyyyMMdd", CultureInfo.InvariantCulture); sqlquery = @"INSERT INTO [dbo].[fileInfo] VALUES ('" + file.Replace("'", "") + "', '" + dt.Date + "')"; SqlCommand sqlcom = new SqlCommand(sqlquery, sqlConnection); sqlcom.ExecuteNonQuery(); } } catch (Exception exception) { using (StreamWriter sw = File.CreateText(LogFolder + "\\" + "ErrorLog_" + currentdatetime + ".log")) { sw.WriteLine(exception.ToString()); } } ---------------------------- Now I can easily select the data from my sql table either in ascending order of date or descending order of date select * from fileInfo order by FileDate desc
@BrundaG-n1f
@BrundaG-n1f Жыл бұрын
I already have a date column in my table but while loading only it should load like consecutive manner
@vak7553
@vak7553 Жыл бұрын
Please also Create a video for capturing errorcolumnname for the bad record in the error log file in sql table Along with the bad record
@learnssis
@learnssis Жыл бұрын
SSIS does not provide the errored column names, thus I am not sure how we can capture it.
@vak7553
@vak7553 Жыл бұрын
@@learnssis how then we can identify which column had an issue
@vak7553
@vak7553 Жыл бұрын
I’m using this piece of code but it’s not helping public override void Inputo_ProcessInputRow(Input0Buffer Row) string errorColumnName = "Unknown Column" ; IDTSComponentMetaData100 metadata = this. ComponentMetaData; //Diagnostic Logging string debugMessage = "Error Column ID: " + Row. ErrorColumn. ToStringO) + " "; // Find the column that has the error foreach IDTSInputColumn100 column in metadata. InputCollection[0] InputColumnCollection) debugMessage += "Column: " + column .Name + ", LineageID: + column.LineageID + " "; if (column.LineageID = Row. ErrorColumn) errorColumnName = column. Name; break; // Assign the error column name to the output_ buffer Row. ErrorCoulumnName = errorCoLumnName; //Write the debugMessage to a file for troubleshooting System. IO. FiLe.AppendAllText("C: |\Users| |vkothari|\Downloads|\SSIS_DEBUGLog.txt", debugMessage)
150 How to move files to month wise folders in ssis
14:13
Learn SSIS
Рет қаралды 1,5 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Learn SQL In 60 Minutes
56:24
Web Dev Simplified
Рет қаралды 2,2 МЛН
133 Explaining Foreach loop container options in detail in ssis
15:15
Running SQL in an Excel Worksheet
22:08
Bob Flisser
Рет қаралды 6 М.
110 How to check if File exists in SSIS
13:08
Learn SSIS
Рет қаралды 10 М.
Comprehending Proc Macros
47:41
Logan Smith
Рет қаралды 24 М.
Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF
28:34
Decomplexify
Рет қаралды 2,2 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН