简体   繁体   English

使用 ADF 将 CSV 个文件导入 SQL 服务器

[英]Importing CSV file(s) into SQL server with ADF

I've a CSV file stored in a blob storage and want to upsert the records in a on-premise SQL server.我有一个存储在 blob 存储中的 CSV 文件,我想将记录更新到本地 SQL 服务器中。 Currently I'm getting errors on inserting date fields.目前我在插入日期字段时遇到错误。 In the CSV file those date fields are typed as a date field.在 CSV 文件中,这些日期字段被键入为日期字段。 In my SQL table they are marked as DateTime2 fields.在我的 SQL 表中,它们被标记为 DateTime2 字段。 In the CSV file I have about 1000 records, 500 of them are seen as correct and 500 as incorrect.在 CSV 文件中,我有大约 1000 条记录,其中 500 条被视为正确,500 条被视为错误。

When I check the file I really don't see a difference in the date fields.当我检查文件时,我真的没有看到日期字段有什么不同。 There is no time hidden or whatever which could actually cause my pipeline to fail.没有隐藏时间或任何实际上可能导致我的管道失败的东西。

What would be a good way to handle those fields?处理这些领域的好方法是什么? In the current situation, as a work around so that the business could continue, I've inserted all the fields as nvarchar(500) fields.在当前情况下,为了让业务能够继续进行,我将所有字段插入为 nvarchar(500) 字段。 So the imports works, but it's not ideal...所以进口有效,但并不理想......

-- update - 更新

I've uploaded an image of the file which I'm importing, removed the fields where I'm not getting errors on.我已经上传了我正在导入的文件的图像,删除了我没有收到错误的字段。 As you can see in the csv file the cells where there is some data are marked as Date fields.正如您在 csv 文件中看到的那样,包含一些数据的单元格被标记为日期字段。

Excel example Excel 例子Excel范例

In ADF all fields are identified as a 'string' field, so maybe that's the problem.在 ADF 中,所有字段都被标识为“字符串”字段,所以这可能就是问题所在。 Never the less I can't change the schema in the import settings.尽管如此,我还是无法更改导入设置中的架构。

ADF identifying them as string ADF 将它们识别为字符串ADF 将它们识别为字符串

In SQL they are set to DateTime2 (setting it to dateTime or date gave the same error).在 SQL 中,它们被设置为 DateTime2(将其设置为 dateTime 或 date 会产生相同的错误)。

Sink field schema汇场模式汇场模式

Here the mapping itself:这里是映射本身:

Source and Sink mapping源和汇映射源和汇映射

Eventually the error that I'm getting, is saying that it can't insert a string value into a datetime field.最终我得到的错误是说它不能将字符串值插入到日期时间字段中。

{
"errorCode": "2200",
"message": "ErrorCode=TypeConversionFailure,Er is een uitzondering opgetreden bij het converteren van de waarde 29-8-2017 voor de kolomnaam TT_STARTDATE van het type String (Precision: , Scale: ) naar type DateTime (Precision: 255, Scale: 7). Aanvullende informatie: String was not recognized as a valid DateTime.",
"failureType": "UserError",
"target": "EMP",
"details": [
    {
        "errorCode": 0,
        "message": "'Type=System.FormatException,Message=String was not recognized as a valid DateTime.,Source=mscorlib,'",
        "details": []
    }
]}

Thanks in advance!提前致谢!

Well i think it is the fomat of the date which is different in excel and what SQL is expecting is creating the error.好吧,我认为这是日期的格式,它在 excel 中是不同的,而 SQL 期望的是创建错误。 I think in Excel you are providing dd-MM-YYYY, may be your SQL is expecting MM-DD-YYYY.我认为在 Excel 中你提供的是 dd-MM-YYYY,可能是你的 SQL 期待的是 MM-DD-YYYY。 I suggest please check this on the SQL side by inserting a record from TSQL using SSMS or other IDE. Once you are sure you can change the format in EXCEL accordingly.我建议请通过使用 SSMS 或其他 IDE 从 TSQL 插入一条记录来在 SQL 端检查这一点。一旦你确定你可以相应地更改 EXCEL 中的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM