由于日期列,SSIS (2008R2) 从 mssql 导入到 mysql 失败
我有一个到 mssql 的 oledb 连接和一个到 mysql 的 ado.net 目标(使用 odbc 驱动程序)。这些表完全相同,所有列都在工作,只有第一列。
收到的错误消息是: [ADO NET 目标 [325]] 错误:数据插入期间发生异常,从提供程序返回的消息是:无法将类型“System.DateTime”的对象转换为类型“System.Char[]”。
我在其他数据类型上看到过类似的问题,但更改为字符串的解决方案在这里不起作用。如果我转换为字符串(长度必须为 29,否则转换步骤将失败),我收到以下错误消息:
[ADO NET Destination [325]] 错误:数据插入期间发生异常,从提供程序返回的消息是:错误 [HY000] [MySQL][ODBC 5.1 驱动程序][mysqld-5.5.15]日期时间值不正确:'2011-03-21第 1 行“LastModificationDate”列的“11:23:48.573000000”
其他可能相关的详细信息: 连接驱动程序- {MySQL ODBC 5.1 驱动程序} 脚本在数据流之前运行 - 设置 sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES' 其他日期时间列正在工作 该列的空值比例相当高 mssql 规范:[LastModificationDate] [日期时间] NULL mysql 规范:LastModificationDate
datetime NULL
有没有人有过此问题的经验并可以提供一些解决它的建议?
I have an oledb connection to mssql and an ado.net destination (with odbc driver used) to mysql. The tables are exectly the same and all the columns are working bar one.
The error message received is:
[ADO NET Destination [325]] Error: An exception has occurred during data insertion, the message returned from the provider is: Unable to cast object of type 'System.DateTime' to type 'System.Char[]'.
I've seen similar questions on other data types but the resolution of changing to string does not work here. If I convert to string (has to be length 29 otherwise the conversion step fails) I get the following error message:
[ADO NET Destination [325]] Error: An exception has occurred during data insertion, the message returned from the provider is: ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.15]Incorrect datetime value: '2011-03-21 11:23:48.573000000' for column 'LastModificationDate' at row 1
Other potentially relevant details:
connection driver- {MySQL ODBC 5.1 Driver}
script run before dataflow - set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES'
Other datetime columns are working
This column has a reasonably high proportion of nulls
mssql spec: [LastModificationDate] [datetime] NULL
mysql spec: LastModificationDate
datetime NULL
Has anyone had experience with this issue and could provide some advice on resolving it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试在查询中使用以下方法将其转换为 sql 服务器端的字符串:
这对我一直有效。
Can you try converting it to string on sql server side in your query using:
This works for me all the time.
这周我也有同样的头痛。我尝试了很多方法。感谢上帝,终于,其中一个成功了。希望它能给你一点点帮助。
对于一些数据类型为Int、datetime、decimal……的列,这里我标识为ColumnA,并将其用作datetime类型。
1.在数据流源中,使用SQL命令检索数据。像 select isnull(ColumnA,'1800-01-01') as ColumnA, C1, C2, ... Cn from Table 一样
确保对具有前面提到的数据类型的所有列使用 Isnull 函数。
2.执行SSIS pkg。它应该有效。
3.回到控制流,在数据流任务下,添加SQL Task控件来替换回来的数据。我的意思是,再次将 ColumnA 从“1800-01-01”更新为 null。
这对我有用。在我的情况下,我无法使用忽略失败选项。因为如果我这样做,我将丢失数千行数据。
I got the same big headache this week. I tried many ways. Thanks God, finnally, one of them worked. Hope it could help you a little bit.
For some columns with the data type of Int, datetime, decimal....,here, I identified as ColumnA, and I used it as datetime type.
1.in Data Flow Source, use SQL Command to retrieve data. Sth like select isnull(ColumnA,'1800-01-01') as ColumnA, C1, C2, ... Cn from Table
Make sure to use Isnull function for all columns with the datatype mentioned before.
2.Excute the SSIS pkg. It should work.
3.Go back to Control Flow, under the data flow task, add SQL Task control to replace the data back. I mean, update the ColumnA from '1800-01-01' to null again.
That works for me. In my situation, I cannot use ignore failure option. Because if I do, I will lose thousands rows of data.