导入CSV文件到SQL服务器...

问题描述:

嗨,大家好, 我想导入CSV文件到SQL服务器数据库,没有成功。我仍然是新手到SQL Server,谢谢。导入CSV文件到SQL服务器...

 
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) 
+1

看到说:“...失败,出现以下错误:”无法删除表'dbo.test',因为它不存在或您没有权限。“。”“ – 2010-05-26 04:42:07

你真的在你的导入两个主要问题:

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.".

好像你想放弃甚至不存在的表。解决方案:不要这样做!

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中VARCHAR列的默认长度太小。将目标列的数据类型更改为VARCHAR(MAX) - 这给你2 GB的空间!这应该是足够的......

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

"Text was truncated or one or more characters had no match in the target code page."

,可能会出现即使当:

  • 源平面文件是Unicode文件

AND

  • 目标列被定义为为nvarchar(最大值)。

这花了我一段时间才弄清楚。

原因

SSIS从扫描所述第一N行和制造受过教育的猜测源文件中的推断的数据类型。由于无休止地反复尝试使其正常工作,它已将数据类型(OutputColumnWidth)的元数据停在某处的50个字符处,导致程序包内部截断。

分辨率

与数据源的“高级”选项卡中的元数据,伪造账目,那么你要如何解决这个问题是什么。尝试通过播放“建议类型”中的设置来重置整个事件,或者逐字段调整设置。在我的情况下(广泛的输入文件)需要真正令人沮丧的迭代次数,但最终你可以使它工作。

+4

+1这个世界是默认的!? – CrazyPyro 2013-07-25 13:31:03

鉴于这件事情非常快,建议在字段的基础上使用建议的类型和调整设置。如果您直接创建最终表,您可能需要稍后增加列宽以供稍后输入数据。我建议只计算导入文件中的行数,并将整个集合扫描为“示例”。少一点可能会导致错误。调整它的时间可能不值得你花时间。

我有同样的问题:

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

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

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

+0

这不是问题的根源,因此没有一个好的答案。 – rene 2014-06-17 15:38:17