首页 文章

将CSV文件导入SQL Server ...

提问于
浏览
8

大家好,我正在尝试将CSV文件导入SQL服务器数据库,但没有成功 . 我仍然是sql server的新手,谢谢 .

Operation stopped...

- Initializing Data Flow Task (Success)

- Initializing Connections (Success)

- Setting SQL Command (Success)

- Setting Source Connection (Success)

- Setting Destination Connection (Success)

- Validating (Success)
    Messages
    * Warning 0x80049304: Data Flow Task 1: Warning: Could not open global shared memory to communicate with performance DLL; data flow performance counters are not available.  To resolve, run this package as an administrator, or on the system's console.
     (SQL Server Import and Export Wizard)


- Prepare for Execute (Success)

- Pre-execute (Success)
    Messages
    * Information 0x402090dc: Data Flow Task 1: The processing of file "D:\test.csv" has started.
     (SQL Server Import and Export Wizard)


- Executing (Error)
    Messages
    * Error 0xc002f210: Drop table(s) SQL Task 1: Executing the query "drop table [dbo].[test]
    " failed with the following error: "Cannot drop the table 'dbo.test', because it does not exist or you do not have permission.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
     (SQL Server Import and Export Wizard)

    * Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column ""Code"" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
     (SQL Server Import and Export Wizard)

    * Error 0xc020902a: Data Flow Task 1: The "output column ""Code"" (38)" failed because truncation occurred, and the truncation row disposition on "output column ""Code"" (38)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
     (SQL Server Import and Export Wizard)

    * Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "D:\test.csv" on data row 21.
     (SQL Server Import and Export Wizard)

    * Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Source - test_csv" (1) returned error code 0xC0202092.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
     (SQL Server Import and Export Wizard)


- Copying to [dbo].[test] (Stopped)

- Post-execute (Success)
    Messages
    * Information 0x402090dd: Data Flow Task 1: The processing of file "D:\test.csv" has ended.
     (SQL Server Import and Export Wizard)

    * Information 0x402090df: Data Flow Task 1: The final commit for the data insertion in "component "Destination - test" (70)" has started.
     (SQL Server Import and Export Wizard)

    * Information 0x402090e0: Data Flow Task 1: The final commit for the data insertion  in "component "Destination - test" (70)" has ended.
     (SQL Server Import and Export Wizard)

    * Information 0x4004300b: Data Flow Task 1: "component "Destination - test" (70)" wrote 0 rows.
     (SQL Server Import and Export Wizard)

6 回答

  • 6

    导入中确实存在两个主要问题:

    错误0xc002f210:删除表SQL任务1:执行查询“drop table [dbo] . [test]”失败,出现以下错误:“无法删除表'dbo.test',因为它不存在或你没有许可 . ” .

    看起来你正试图放下一张甚至不存在的 table . 解决方案:就是不要这样做!

    错误0xc02020a1:数据流任务1:数据转换失败 . 列“”代码“”的数据转换返回状态值4和状态文本“文本被截断,或者目标代码页中的一个或多个字符不匹配 . ” .

    您的列"Code"显然比目标表中的结果列长 . 检查映射 - 可能这是一个非常长的字符串,SQL Server中VARCHAR列的默认长度太小 . 将目标列的数据类型更改为例如 VARCHAR(MAX) - 为您提供2 GB的空间!那应该够了......

    此外,"Code"列似乎包含SQL Server中当前所选代码页中不存在的字符 - 您可以在导入之前删除这些额外的特殊字符吗?如果没有,您可能需要使用 NVARCHAR(MAX) 作为目标列的数据类型,以允许它为其字符使用Unicode(从而支持输入字符串中最奇特的字符) .

  • 12

    “文本被截断,或者目标代码页中的一个或多个字符不匹配 . ”

    甚至可能发生在:

    • 您的源平面文件是UNICODE文件

    • 您的目标列定义为nvarchar(max) .

    我花了一段时间才弄明白 .

    Cause

    SSIS通过扫描前N行并进行有根据的猜测来推断源文件中的数据类型 . 由于无休止地重复尝试使其工作,它已将数据类型(OutputColumnWidth)的元数据停放在某处的某处50个字符,从而导致包内部截断 .

    Resolution

    摆弄数据源的“高级”选项卡中的元数据是您要解决问题的方法 . 尝试使用“建议类型”中的设置重置整个内容,或逐个字段地调整设置 . 在我的案例中需要一个真正令人沮丧的迭代次数(广泛的输入文件),但最终你可以让它工作 .

  • 0

    我有同样的问题:

    Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "target" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
    

    解决方案是转到“高级”并将列宽更改为255 .

  • 1

    或者您也可以通过转到高级检查文本的大小,然后检查建议,然后将字符串转换为unicode字符串 . 它有助于解决字符串相关的错误 . 我最近一直面对他们!

  • 0

    鉴于此事情非常快,建议逐个字段地使用建议类型和调整设置 . 如果要直接创建最终表,则可能需要稍微增加列宽以便以后输入数据 . 我建议只计算导入文件中的行数,并将整个集扫描为“样本” . 任何不足都可能导致错误 . 调整它的时间可能不值得你花时间 .

  • 1

    对于“错误0xc02020a1”,我的案例是通过从CSV文件端更改单元格格式来解决的:(通过excel打开CSV文件>>将单元格格式从百分比更改为常规然后保存),这解决了我的情况 .

相关问题