Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Import failed with BCP and XML-Format-File

Author  Topic 

Fasse
Starting Member

5 Posts

Posted - 2008-01-21 : 11:25:14
I have a table with 2 row:

CREATE TABLE [dbo].[EABL](
[DSID] [int] IDENTITY(1,1) NOT NULL,
[ABLBELNR] [nvarchar](255) NULL)


If I make a XML formatfile which look like this:
<?xml version="1.0"?>
<BCPFORMAT ...>
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="20"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="ABLBELNR" xsi:type="SQLNVARCHAR"/>
</ROW>
</BCPFORMAT>

then the import failed with the following error message:
[Microsoft][SQL Native Client]All bound columns are not read-only


If I delete the identity column then the import works correct.

What can I do, so that I can import with the identity column ?

Thanks for you help
Fasse

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-21 : 15:54:29
Have to enable identity insert with 'set identity_insert on'.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-21 : 16:10:32
BCP has switch to keep identity values from source file too
Go to Top of Page

Fasse
Starting Member

5 Posts

Posted - 2008-01-21 : 16:29:22
Thanks for your response.

But I don't want to set the identity manually. Sql-Server should fill them automatically. The problem is, that BCP gave me an error and didn't fill the 2. column :(
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-21 : 16:44:34
Tried with -E option in bcp as Russell said?
Go to Top of Page

Fasse
Starting Member

5 Posts

Posted - 2008-01-21 : 17:13:58
Ok, I will try it tomorrow.

Thanks.
Go to Top of Page

Fasse
Starting Member

5 Posts

Posted - 2008-01-22 : 06:17:41
I found the problem.

Using XML in the format file of BCP doesn't allow you to ignore one column in the database (in my case the identity column). So I have to create a view without the identity column and make the insert into this view or to use the "old" format file without XML.
Go to Top of Page
   

- Advertisement -