Domanda

I am stuck in creating bcp format file. My client is using MSSQL 2005 and I am remotely connecting through RDC. I am creating format file on the target client MSSQL Server using the following command,

bcp myDatabase.TableName format nul -c -x -f someFile..xml -T

but the it prompt me with error

An Error has occured while establishing a connection to the server.


My View pointing to a table having structure as under:

Colum Name          DataType
SKU                 Varchar(20)
ASIN                Varchar(20)
Price               Float
Quantity            Int
MarketplaceTitle    Varchar(50)

Note: I have been through many similar questions but had no luck.

Anyone can please provide me with a format file for the above View?

Thanks in advance.

È stato utile?

Soluzione

It sounds like your issue is actually connecting to your database, not the format file.

I've created a quick test:

-- DROP TABLE dbo.Test
CREATE TABLE dbo.Test(
SKU                 Varchar(20),
[ASIN]              Varchar(20),
Price               Float,
Quantity            Int,
MarketplaceTitle    Varchar(50)
);

and here's a slightly more verbose syntax:

bcp YourDatabaseName.dbo.Test format nul -c -x -f c:\YourDir\format.xml -T -S YourServerName

so for me, this looks like this:

bcp sandbox.dbo.Test format nul -c -x -f c:\Test\format.xml -T -S "(local)"

Here's the file generated:

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <RECORD>
  <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="20" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="2" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="20" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="30"/>
  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="12"/>
  <FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="50" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
 </RECORD>
 <ROW>
  <COLUMN SOURCE="1" NAME="SKU" xsi:type="SQLVARYCHAR"/>
  <COLUMN SOURCE="2" NAME="ASIN" xsi:type="SQLVARYCHAR"/>
  <COLUMN SOURCE="3" NAME="Price" xsi:type="SQLFLT8"/>
  <COLUMN SOURCE="4" NAME="Quantity" xsi:type="SQLINT"/>
  <COLUMN SOURCE="5" NAME="MarketplaceTitle" xsi:type="SQLVARYCHAR"/>
 </ROW>
</BCPFORMAT>

HTH.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top