Error on importing a file to database

  • Dear All,

    I have problem with dat file which I have to import it into database by code below:

    the problem is: if there is a line which don't have close tag " the importing get error and any line is not import.

    so,how can I import the lines which are corrected I mean the line which has "" and ""? and delete the incorrect line if posible?

    Please help.

    /*my example dat file */

    Beginning of annotation phase.

    Beginning of the graphics drawing.

    Graphic count: 0.

    End of the graphics drawing.

    Beginning of the labeling.

    /*end my dat file*/

    /*my import code */

    DECLARE @xml XML

    SELECT @xml = BulkColumn

    FROM OPENROWSET

    (

    BULK '\\ServerName\Sharefolder\FileName.Dat', SINGLE_BLOB

    ) X

    INSERT INTO dbo.TestLog (Code,Time,Target,Machine,Elapsed)

    SELECT

    C.value('@code', 'varchar(50)') as [Code],

    C.value('@time', 'datetime') as [Time],

    C.value('@target', 'varchar(max)') as [Target],

    C.value('@machine', 'varchar(50)') as [Machine],

    C.value('@elapsed', 'varchar(50)') as [Elapsed]

    FROM @xml.nodes('/Msg') X(C)

    /* end my code */

  • Can you add to your process a step which checks that the input XML is well formed?

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply