将 CSV 文件导入 SQL Server 时操作停止

发布于 2024-09-02 19:20:39 字数 1782 浏览 4 评论 0原文

我正在尝试将 CSV 文件导入 SQL Server 数据库,但没有成功。我仍然是 sql server 的新手。

操作停止...

  • 正在初始化数据流任务(成功)

  • 初始化连接(成功)

  • 设置SQL命令(成功)

  • 设置源连接(成功)

  • 设置目标连接(成功)

  • 验证(成功) 消息

    • 警告 0x80049304:数据流任务 1:警告:无法打开全局共享内存以与性能 DLL 通信;数据流性能计数器不可用。要解决此问题,请以管理员身份运行此软件包,或在系统控制台上运行。 (SQL Server 导入和导出向导)
  • 准备执行(成功)

  • 预执行(成功) 消息

    • 信息 0x402090dc:数据流任务 1:文件“D:\test.csv”的处理已开始。 (SQL Server 导入和导出向导)
  • 正在执行(错误) 消息

    • 错误 0xc002f210:删除表 SQL 任务 1:执行查询“drop table [dbo].[test]” ”失败并出现以下错误:“无法删除表“dbo.test”,因为它不存在或您没有权限。”。可能的失败原因:查询问题、“ResultSet”属性未正确设置、参数设置不正确,或者连接未正确建立。 (SQL Server导入和导出向导)

    • 错误 0xc02020a1:数据流任务 1:数据转换失败。 “代码”列的数据转换返回状态值 4 和状态文本“文本被截断或一个或多个字符在目标代码页中不匹配。”。 (SQL Server导入和导出向导)

    • 错误 0xc020902a:数据流任务 1:“输出列“Code”(38)”因发生截断而失败,且“输出列“Code”(38)”上的截断行处置失败指定截断失败。指定组件的指定对象发生截断错误。 (SQL Server导入和导出向导)

    • 错误 0xc0202092:数据流任务 1:处理数据行 21 上的文件“D:\test.csv”时出错。 (SQL Server导入和导出向导)

    • 错误 0xc0047038:数据流任务 1:SSIS 错误代码 DTS_E_PRIMEOUTPUTFAILED。组件“Source - test_csv”(1) 上的 PrimeOutput 方法返回错误代码 0xC0202092。当管道引擎调用 PrimeOutput() 时,组件返回失败代码。失败代码的含义由组件定义,但错误是致命的,管道停止执行。在此之前可能会发布错误消息,其中包含有关失败的更多信息。 (SQL Server导入和导出向导)

  • 复制到 [dbo].[test](已停止)

  • 执行后(成功) 消息

    • 信息0x402090dd:数据流任务1:文件“D:\test.csv”的处理已结束。 (SQL Server导入和导出向导)

    • 信息 0x402090df:数据流任务 1:“组件“目标 - 测试”(70)”中数据插入的最终提交已开始。 (SQL Server导入和导出向导)

    • 信息 0x402090e0:数据流任务 1:“组件“目标 - 测试”(70)”中数据插入的最终提交已结束。 (SQL Server导入和导出向导)

    • 信息 0x4004300b:数据流任务 1:“组件“目标 - 测试”(70)”写入了 0 行。 (SQL Server 导入和导出向导)

I am trying to import CSV file to SQL server database, with no success. I am still newbie to 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

∝单色的世界 2024-09-09 19:20:39

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

甚至在以下情况下也可能发生:

  • 源平面文件是 UNICODE 文件

并且

  • 目标列定义为 nvarchar(max)。

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

原因

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

解决方案

摆弄数据源的“高级”选项卡中的元数据就是您想要解决问题的方法,尝试通过使用“建议”中的设置来重置整个问题 类型”,或者逐个字段地调整设置。在我的例子中(广泛的输入文件),确实需要大量的迭代,但最终你可以让它工作。

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

may occur EVEN when:

  • your source flat file is a UNICODE file

AND

  • your target column is defined as nvarchar(max).

This took me a while to figure out.

Cause

SSIS infers data types in the source file from scanning the first N rows and making an educated guess. Due to endlessly repeated attempts to get it to work, it had parked the metadata for the data type (OutputColumnWidth) to 50 characters somewhere along the way, causing truncation internal to the package.

Resolution

Fiddling with the metadata in the Data Source's "Advanced" tab is then what you want to do to resolve the problem. Try to reset the whole thing by playing with the settings in "Suggest Types", or tweak settings on a field-by-field basis. A truly discouraging amount of iterations was needed in my case (broad input file), but eventually you can get it to work.

琉璃梦幻 2024-09-09 19:20:39

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

错误 0xc002f210:删除表 SQL
任务 1:执行查询“drop
表 [dbo].[test] " 失败
以下错误:“无法删除
表'dbo.test',因为它没有
存在或者您没有权限。”。

看起来您正在尝试删除一个甚至不存在的表。解决方案:不要这样做!

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

您的列“Code”显然比目标表中的结果列长。检查映射 - 也许这是一个非常长的字符串,并且是 SQL Server 中 VARCHAR 列的默认长度太小了。将目标列的数据类型更改为 VARCHAR(MAX) - 这将为您提供 2 GByte 的空间!

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

You really have two major problems in your import:

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

It seems like you're trying to drop a table that doesn't even exist. Solution: just don't do it!

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

Your column "Code" obviously is longer than the resulting column that you have in your target table. Check the mappings - maybe this is a very long character string, and the default length for the VARCHAR column in SQL Server is too small. Change the target column's data type to e.g. VARCHAR(MAX) - that gives you 2 GByte of space! That should be enough....

Also it seems that "Code" column contains characters that aren't present in your currently selected code page in SQL Server - can you strip those extra special characters before importing? If not, you might need to use NVARCHAR(MAX) for your target column's data type in order to allow it to use Unicode for its characters (thus supporting even the most exotic of characters in your input string).

唔猫 2024-09-09 19:20:39

我遇到了同样的问题:

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。

I had the same problem:

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

The solution was to go to "Advanced" and change the column width to 255.

孤城病女 2024-09-09 19:20:39

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

Or you could also check the size of the text by going to advanced, then checking the suggestion, and then convert the string to unicode string. it helps in resolving string related error. I have been facing them a lot recently!

九厘米的零° 2024-09-09 19:20:39

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

Given the fact that this thing is very fast it is advisable to use Suggested Types and tweak settings on a field by field basis. If you are creating a final table directly you may want to increase the column widths a bit for later data entry. I suggest just counting the number of rows in your import file and scan the whole set as your 'sample'. Anything less could result in errors. The time to tweak it is probably not worth your time.

つ低調成傷 2024-09-09 19:20:39

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

For "Error 0xc02020a1" my case was solved by changing the cell Format from CSV file side:
(Open the CSV file by excel>>change the cell format from percent to general then save it), that solved my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文