我有一个 CSV 文件,其中以 {LF} 分隔每一行,还有一个日期列,日期格式为 "12/20/2010"
(包括引号)
我的目标列是 SQL Server 2008 数据库日期类型表(不是日期时间)
在我的平面文件连接管理器中,我已将日期列配置为数据类型 date [DT_DATE]
,其中 TextQualified 设置为 true,并且柱子分隔符为 {LF}
(它是每行的最后一列)。我将文本限定符设置为 "
当我尝试将其加载到 OLE 目标中时,出现以下错误
[TRN_DORPS [760]] 错误:SSIS 错误代码 DTS_E_OLEDBERROR。发生 OLE DB 错误。错误代码:0x80004005。
OLE DB 记录可用。来源:“Microsoft OLE DB Provider for SQL Server” Hresult:0x80004005 描述:“转换规范的字符值无效。”。
[TRN_DORPS [760]] 错误:输入“OLE DB 目标输入”(773) 上的输入列“CYCLE_DATE”(874) 存在错误。返回的列状态为:“由于可能会丢失数据,因此无法转换该值。”。
如果我附加数据查看器,管道中的值是 2010-12-20 00:00:00.0000000
- 这个时间组件是导致问题的原因吗?我尝试使用 (DT_DATE)(DT_DBDATE)[CYCLE_DATE]
删除时间组件,但无济于事,因为它在管道中保持不变
I have a CSV file with a {LF} delimiting each row and a date column with the date format as "12/20/2010"
(including quotation marks)
My destination column is a SQL Server 2008 database table of type date (not datetime)
In my Flat File Connection Manager, I have configured the date column to be data type date [DT_DATE]
with TextQualified set to true and the column delimiter as {LF}
(it is the last column on each row). I have the text qualifier set to "
When I try to load this into an OLE Destination I get the following error
[TRN_DORPS [760]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "Invalid character value for cast specification.".
[TRN_DORPS [760]] Error: There was an error with input column ""CYCLE_DATE"" (874) on input "OLE DB Destination Input" (773). The column status returned was: "The value could not be converted because of a potential loss of data.".
If I attach a data viewer, the value in the pipeline is 2010-12-20 00:00:00.0000000
- is this time component what's causing the problem? I try to strip out the time component with (DT_DATE)(DT_DBDATE)[CYCLE_DATE]
but to no avail as it stays the same in the pipeline
发布评论
评论(3)
我最终能够通过将平面文件连接中的列类型设置为“数据库日期 [DT_DBDATE]”类型来解决该解决方案
显然这些日期格式之间的差异如下:
DT_DATE
由年、月、日、和小时组成的日期结构。
DT_DBDATE
由年、月、日组成的日期结构。
DT_DBTIMESTAMP
由年、月、时、分、秒和分数组成的时间戳结构
通过将列类型更改为 DT_DBDATE,问题得到解决 - 我附加了一个数据查看器,CYCLE_DATE 值现在只是“12/20/2010”,没有时间组件,显然解决了这个问题。
I was ultimately able to resolve the solution by setting the column type in the flat file connection to be of type "database date [DT_DBDATE]"
Apparently the differences between these date formats are as follow:
DT_DATE
A date structure that consists of year, month, day, and hour.
DT_DBDATE
A date structure that consists of year, month, and day.
DT_DBTIMESTAMP
A timestamp structure that consists of year, month, hour, minute, second, and fraction
By changing the column type to DT_DBDATE the issue was resolved - I attached a Data Viewer and the CYCLE_DATE value was now simply "12/20/2010" without a time component, which apparently resolved the issue.
我的日期值错误,即我有一个针对
2022-09-31
运行的查询,这是不正确的,因为 9 月份不是 31 天的月份。将其更改为2022-09-30
效果很好。I had a wrong value for a date, i.e I had a query that was running against
2022-09-31
which is incorrect as the month of September is not a 31 days month. Changing it to2022-09-30
worked fine.为了模拟您面临的问题,我使用
SSIS 2008 R2
和SQL Server 2008 R2
后端创建了以下示例。该示例基于我从您的问题中收集到的内容。此示例未提供解决方案,但它可能会帮助您确定您的情况中问题可能出在哪里。创建一个简单的 CSV 文件,其中包含两列,即订单号和订单日期。正如您在问题中提到的,两列的值都用双引号 (") 限定,行也以换行符 (\n) 结尾,日期是最后一列。下面的屏幕截图是使用 ,可以显示屏幕截图中的特殊字符 LF 表示换行。
="http://notepad-plus-plus.org/" rel="noreferrer" > src="https://i.sstatic.net/xz0yi.png" alt="Orders file">
在 SQL Server 数据库中创建了一个名为
dbo.Destination
的简单表来填充 CSV 文件数据下面给出了使用 SSIS 包创建表的脚本,我使用 OLE DB 连接创建了两个连接管理器来连接到 SQL Server 数据库。平面文件 平面文件连接管理器
配置为读取 CSV 文件,设置如下所示。红色箭头表示所做的更改。
为平面文件连接管理器提供名称。浏览到 CSV 文件的位置并选择文件路径。输入双引号 (
"
) 作为文本限定符。将标题行分隔符从 {CR}{LF} 更改为{LF}
。此标题行分隔符更改也反映了在“列”部分中。部分中未进行任何更改。
将列名称从 Column0 更改为
OrderNumber
。src="https://i.sstatic.net/GkaC2.png" alt = src="https://i.sstatic.net/OqrZ0.png" alt="高级列 OrderNumber">
将列名称从 Column1 更改为
OrderDate
并且也更改这数据类型为日期 [DT_DATE]
平面文件连接中数据的预览 在
SSIS 包的
Control Flow
选项卡上,放置了 <代码>数据流任务。在数据流任务中,放置了一个
平面文件源
和一个OLE DB 目标
。平面文件源
配置为使用 FlatFile 连接读取 CSV 文件数据经理。下面的三个屏幕截图显示了平面文件源组件的配置方式。已配置
OLE DB 目标
组件接受来自平面文件源的数据并将其插入到名为dbo.Destination
的 SQL Server 数据库表中。下面的三个屏幕截图显示了 OLE DB 目标组件的配置方式。使用以下 5 中提到的步骤屏幕截图中,我在平面文件源和 OLE DB 目标之间的流上添加了一个数据查看器。
在运行包之前,我验证了表中存在的初始数据。它目前是空的,因为我使用本文开头提供的脚本创建了它。
执行了包,包执行暂时暂停,以显示从平面文件源到 OLE DB 目标的数据流数据查看器。我单击运行按钮继续执行。
包已成功执行。
平面文件源数据已成功插入到表
dbo.Destination
中。这是表 dbo.Destination 的布局。正如您所看到的,字段 OrderDate 的数据类型为 date,并且包仍然继续正确插入数据。
这篇文章虽然不是解决方案。希望可以帮助您找出您的场景中问题可能出在哪里。
In order to simulate the issue that you are facing, I created the following sample using
SSIS 2008 R2
withSQL Server 2008 R2
backend. The example is based on what I gathered from your question. This example doesn't provide a solution but it might help you to identify where the problem could be in your case.Created a simple CSV file with two columns namely order number and order date. As you had mentioned in your question, values of both the columns are qualified with double quotes (") and also the lines end with Line Feed (\n) with the date being the last column. The below screenshot was taken using Notepad++, which can display the special characters in a file. LF in the screenshot denotes Line Feed.
Created a simple table named
dbo.Destination
in the SQL Server database to populate the CSV file data using SSIS package. Create script for the table is given below.On the SSIS package, I created two connection managers. SQLServer was created using the OLE DB Connection to connect to the SQL Server database. FlatFile is a flat file connection manager.
Flat file connection manager was configured to read the CSV file and the settings are shown below. The red arrows indicate the changes made.
Provided a name to the flat file connection manager. Browsed to the location of the CSV file and selected the file path. Entered the double quote (
"
) as the text qualifier. Changed the Header row delimiter from {CR}{LF} to{LF}
. This header row delimiter change also reflects on the Columns section.No changes were made in the Columns section.
Changed the column name from Column0 to
OrderNumber
.Changed the column name from Column1 to
OrderDate
and also changed the data type todate [DT_DATE]
Preview of the data within the flat file connection manager looks good.
On the
Control Flow
tab of the SSIS package, placed aData Flow Task
.Within the Data Flow Task, placed a
Flat File Source
and anOLE DB Destination
.The
Flat File Source
was configured to read the CSV file data using the FlatFile connection manager. Below three screenshots show how the flat file source component was configured.The
OLE DB Destination
component was configured to accept the data from Flat File Source and insert it into SQL Server database table nameddbo.Destination
. Below three screenshots show how the OLE DB Destination component was configured.Using the steps mentioned in the below 5 screenshots, I added a data viewer on the flow between the Flat File Source and OLE DB Destination.
Before running the package, I verified the initial data present in the table. It is currently empty because I created this using the script provided at the beginning of this post.
Executed the package and the package execution temporarily paused to display the data flowing from Flat File Source to OLE DB Destination in the data viewer. I clicked on the run button to proceed with the execution.
The package executed successfully.
Flat file source data was inserted successfully into the table
dbo.Destination
.Here is the layout of the table dbo.Destination. As you can see, the field OrderDate is of data type date and the package still continued to insert the data correctly.
This post even though is not a solution. Hopefully helps you to find out where the problem could be in your scenario.