T-SQL,BULK INSERT / XML格式文件问题

时间:2015-10-12 06:39:27

标签: sql-server xml csv sql-server-2012 bulkinsert

我尝试在SQL Server Express 2014数据库中导入csv文件。这个csv文件只有一个字段是"所限定的文本,所以我必须使用带有批量插入功能的格式文件。

当我甚至尝试阅读我的csv时,我不断得到以下错误

错误消息

Msg 4857, Level 16, State 1, Line 1
Line 7 in format file "C:\formatfile.xml": Attribute "type" could not be specified for this type.

SQL语句

    SELECT
    a.*
    FROM OPENROWSET
    (
    BULK 'C:\MyFile.csv',
    FORMATFILE = 'C:\formatfile.xml',
    FIRSTROW = 2
    ) AS a;

XML格式文件

    <?xml version="1.0"?>
    <BCPFORMAT 
        xmlns="https://schemas.microsoft.com/sqlserver/2004/bulkload/format"
        xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
    />
    <RECORD>
        <FIELD ID="1" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="2" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="3" xsi:type="CharTerm" TERMINATOR=',"' />
        <FIELD ID="4" xsi:type="CharTerm" TERMINATOR='",' />
        <FIELD ID="5" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="6" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="7" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="8" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="9" xsi:type="CharTerm" TERMINATOR=',' />
        <FIELD ID="10" xsi:type="CharTerm" TERMINATOR='\n' />
    </RECORD>

    <ROW>
        <COLUMN SOURCE="1" NAME="System Name" xsi:type="SQLNVARCHAR" /> 
        <COLUMN SOURCE="2" NAME="IP Address" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="3" NAME="Domain" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="4" NAME="Tags" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="5" NAME="DAT Version (VirusScan Enterprise)" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="6" NAME="Product Version (VirusScan Enterprise)" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="7" NAME="Engine Version (VirusScan Enterprise)" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="8" NAME="Engine (x64) Version (VirusScan Enterprise)" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="9" NAME="OS Type" xsi:type="SQLNVARCHAR" />
        <COLUMN SOURCE="10" NAME="Last Communication" xsi:type="SQLNVARCHAR" />
    </ROW>
    </BCPFORMAT>

我的csv文件的示例行

    System Name,IP Address,Domain,Tags,DAT Version (VirusScan Enterprise),Product Version (VirusScan Enterprise),Engine Version (VirusScan Enterprise),Engine (x64) Version (VirusScan Enterprise),OS Type,Last Communication
    COMPUTER1,192.168.1.1,EUROPE,"Clients,Workstations",7940.0000,8.8.0.1247,5700.7163,N/A,Windows 7,9/26/15 5:54:36 PM

任何建议都将不胜感激: - )

0 个答案:

没有答案