SSIS 中的平面文件源错误输出连接
我在 SSIS 中有一个平面文件源连接。我创建了一个用于错误输出的平面文件目标连接。我已经用红色箭头连接了它。问题在于,即使平面文件源中没有错误,也会创建错误输出文件。即使没有错误,“错误平面文件目标”也始终变为绿色。怎么解决呢。提前致谢
I have a flat file source connection in SSIS. I have created one flat file destination connection for error output. I have connected it with red arrow. The problem is that the error output file is created even if there is no error in the flat file source. The "Error Flat file Destination" always turns green even if no error. How to solve it . Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许,您已经找到了解决方案。我希望这可以帮助那些寻找解决这个问题的人。
SSIS 中没有可用的内置数据流任务设置来执行此操作。您可以在数据流任务中使用行计数转换并结合控制流上的文件系统任务来实现此目的。
以下是有关如何执行此操作的分步过程。在此示例中,我使用了一个名为
Country_State.csv
的 csv 文件,其中包含国家/地区和州作为源文件。场景:
示例包将读取该文件,然后写入名为
Destination.txt
的文本文件。在这种情况下,将创建错误文件Error.txt
,但如果没有错误,则稍后将其删除。在这里,我将文件存储在路径c:\temp\
分步流程:
Source
连接应指向 csv 文件路径c:\temp\Country_State.csv
。有关此文件的内容,请参阅屏幕截图 #2。Destination
连接应指向名为c:\temp\Destination.txt
的文本文件。Error
连接应指向名为c:\temp\Error.txt
的文本文件。ErrorCount
的数据类型 Int32 变量。数据流任务
,然后放置一个文件系统任务
。表达式
并将值@ErrorCount == 0
粘贴到表达式文本框。Source
连接管理器。Destination
连接管理器。Row Count
转换放置在数据流选项卡上,并将其配置为使用变量User:ErrorCount
。Error
连接管理器。Error
连接将行计数的输出连接到平面文件目标。删除文件
,并将SourceConnection设置为错误
。请参阅屏幕截图#5。C:\temp
的内容如屏幕截图 #6 所示。C:\temp
的内容如屏幕截图 #9 所示。Source
连接管理器上的第二列更改为整数(即使状态名称是字符串),以便数据流任务重定向到Error
输出。C:\temp
的内容如屏幕截图#12所示。请注意,即使没有成功的行,文件 Destination.txt 仍然存在。这是因为该示例仅删除错误文件(如果该文件为空)。类似的逻辑可用于删除空的目标文件。
希望有帮助。
屏幕截图 #1:
屏幕截图 #2:
屏幕截图 #3:
屏幕截图 #4:
屏幕截图 #5 :
屏幕截图#6:
屏幕截图 #7:
屏幕截图 #8:
屏幕截图 #9:
< img src="https://i.sstatic.net/qhjCy.png" alt="9">
屏幕截图 #10:
屏幕截图 #11:
屏幕截图#12:
Probably, you have already found a solution. I hope this might help someone looking for a solution to this problem.
There is no in-built data flow task setting available in SSIS to do this. You can use
Row Count
transformation inside Data Flow task combined withFile System Task
on the Control Flow to achieve this.Here is step-by-step process on how to do this. In this example, I have used a csv file named
Country_State.csv
containing countries and states as the source file.Scenario:
The sample package will read the file and then write to a text file named
Destination.txt
. In this scenario, the error fileError.txt
will be created but later deleted if there are no errors. Here, I have the files stored in the pathc:\temp\
Step by step flow:
Source
connection should point to the csv file pathc:\temp\Country_State.csv
. Refer screenshot #2 for the contents of this file.Destination
connection should point to a text file namedc:\temp\Destination.txt
.Error
connection should point to a text file namedc:\temp\Error.txt
.ErrorCount
.Data Flow Task
and then place aFile System Task
.Expression
and paste the value@ErrorCount == 0
in the Expression textbox.Source
connection manager.Destination
connection manager.Row Count
transformation on the data flow tab and configure it to use the VariableUser:ErrorCount
.Error
connection manager.Error
connection.Delete file
and set the SourceConnection toError
. Refer screenshot #5.C:\temp
before package execution are shown in screenshot #6.C:\temp
after package execution are shown in screenshot #9.Source
connection manager to integer (even though state names are strings) so that the data flow task redirects to theError
output.C:\temp
after Scenario 2 package execution are shown in screenshot #12. Notice that the file Destination.txt is present even though there were no successful rows. This is because the example deletes only the Error file if it is empty.Similar logic can be used to delete a empty Destination file.
Hope that helps.
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10:
Screenshot #11:
Screenshot #12: