Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @[User::ErrorCount] > 0
- "C:\Your Folder\" + (DT_STR, 4, 1252)DATEPART("Year", GETDATE()) + "_"
- + (DT_STR, 2, 1252)DATEPART("Month", GETDATE()) + "_"
- + (DT_STR, 2, 1252)DATEPART("Day", GETDATE()) +"_"
- + "ErrorFiles.txt"
- IF(OBJECT_ID(N'YourDatabase.DBO.ERRORFILES') IS NOT NULL)
- BEGIN
- DROP TABLE YourDatabase.DBO.ERRORFILES
- END
- CREATE TABLE YourDatabase.DBO.ERRORFILES
- (
- FOLDERNAME VARCHAR(100),
- [FILENAME] VARCHAR(100)
- )
- if (Convert.ToInt32(Dts.Variables["User::ErrorCount"].Value.ToString()) == 0)
- {
- string connString = @"Data Source=YourSQLServerInstance;Initial Catalog=YourDatabase;Integrated Security=SSPI";
- string cmd = @"Insert into dbo.ErrorFiles (FolderName,[FileName]) values (@folderName, @fileName)";
- //parse variable with file that caused error
- string errorFileFullName = Dts.Variables["User::NameForTable"].Value.ToString();
- //get folder
- string errorFolderName = Path.GetDirectoryName(errorFileFullName);
- //get only file name
- string errorFileName = Path.GetFileName(errorFileFullName);
- using (SqlConnection conn = new SqlConnection(connString))
- {
- SqlCommand sql = new SqlCommand(cmd, conn);
- SqlParameter pFolderName = new SqlParameter("@folderName", SqlDbType.VarChar);
- pFolderName.Direction = ParameterDirection.Input;
- pFolderName.Value = errorFolderName;
- pFolderName.Size = 100;
- SqlParameter pFileName = new SqlParameter("@fileName", SqlDbType.VarChar);
- pFileName.Direction = ParameterDirection.Input;
- pFileName.Value = errorFileName;
- pFileName.Size = 100;
- sql.Parameters.Add(pFolderName);
- sql.Parameters.Add(pFileName);
- conn.Open();
- sql.ExecuteNonQuery();
- //avoid failing Foreach Loop so other files are processed
- Dts.Variables["System::Propagate"].Value = false;
- //prevent event handler from firing multiple times.
- Dts.Variables["User::ErrorCount"].Value = 1;
- }
- }
Add Comment
Please, Sign In to add comment