Guest User

Untitled

a guest
Jan 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. @[User::ErrorCount] > 0
  2.  
  3. "C:\Your Folder\" + (DT_STR, 4, 1252)DATEPART("Year", GETDATE()) + "_"
  4. + (DT_STR, 2, 1252)DATEPART("Month", GETDATE()) + "_"
  5. + (DT_STR, 2, 1252)DATEPART("Day", GETDATE()) +"_"
  6. + "ErrorFiles.txt"
  7.  
  8. IF(OBJECT_ID(N'YourDatabase.DBO.ERRORFILES') IS NOT NULL)
  9. BEGIN
  10. DROP TABLE YourDatabase.DBO.ERRORFILES
  11. END
  12.  
  13. CREATE TABLE YourDatabase.DBO.ERRORFILES
  14. (
  15. FOLDERNAME VARCHAR(100),
  16. [FILENAME] VARCHAR(100)
  17. )
  18.  
  19. if (Convert.ToInt32(Dts.Variables["User::ErrorCount"].Value.ToString()) == 0)
  20. {
  21. string connString = @"Data Source=YourSQLServerInstance;Initial Catalog=YourDatabase;Integrated Security=SSPI";
  22.  
  23. string cmd = @"Insert into dbo.ErrorFiles (FolderName,[FileName]) values (@folderName, @fileName)";
  24.  
  25. //parse variable with file that caused error
  26. string errorFileFullName = Dts.Variables["User::NameForTable"].Value.ToString();
  27.  
  28. //get folder
  29. string errorFolderName = Path.GetDirectoryName(errorFileFullName);
  30. //get only file name
  31. string errorFileName = Path.GetFileName(errorFileFullName);
  32.  
  33. using (SqlConnection conn = new SqlConnection(connString))
  34. {
  35. SqlCommand sql = new SqlCommand(cmd, conn);
  36.  
  37. SqlParameter pFolderName = new SqlParameter("@folderName", SqlDbType.VarChar);
  38. pFolderName.Direction = ParameterDirection.Input;
  39. pFolderName.Value = errorFolderName;
  40. pFolderName.Size = 100;
  41.  
  42. SqlParameter pFileName = new SqlParameter("@fileName", SqlDbType.VarChar);
  43. pFileName.Direction = ParameterDirection.Input;
  44. pFileName.Value = errorFileName;
  45. pFileName.Size = 100;
  46.  
  47. sql.Parameters.Add(pFolderName);
  48. sql.Parameters.Add(pFileName);
  49.  
  50. conn.Open();
  51.  
  52. sql.ExecuteNonQuery();
  53.  
  54. //avoid failing Foreach Loop so other files are processed
  55. Dts.Variables["System::Propagate"].Value = false;
  56.  
  57. //prevent event handler from firing multiple times.
  58. Dts.Variables["User::ErrorCount"].Value = 1;
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment