Link to home
Start Free TrialLog in
Avatar of MPI_IT
MPI_ITFlag for United States of America

asked on

xml file from sql server using bcp

I am trying to auto-generate xml file from sql server 2005 using bcp.
I have a stored procedure callled sp_Ap. I use "for xml auto, root("Iss"),elements" to get the required format.It generates the file fine.
My problem is when I try to generate it using bcp utility(I need to set it up to run automatically), it
only generates part of the file and error out in the middle.
This is what I used.
EXEC xp_cmdshell 'bcp "exec ErpLnX.dbo.sp_Ap" QUERYOUT \\va\users\L\Testing.xml -c -T'.

I checked the data and I don't see anything different on that line. Please help.

Errors getting :
---------------
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


End tag 'Sales' does not match the start tag 'SalesOrder'. Error processing resource 'file:///C:/Documents and Settings/lpo...

-----------------------
Avatar of lozzamoore
lozzamoore
Flag of United Kingdom of Great Britain and Northern Ireland image

I've just tried a similar approach with a database I have here, across a very large table, and all works ok. How many rows are returned in your dataset?

It looks like the error you posted is actually when trying to open the file in an XML aware application that is complaining about the data being an XML fragment (which FOR XML AUTO produces), rather than a document.

Can you check if you actually get an error returned during the BCP call by running it manually?
Otherwise, open the XML in Notepad and see if it looks ok.

Hope that helps,

Regards,
Avatar of MPI_IT

ASKER

Maximum number of rows so far is around 100. Today morning, I tried when there was only one line and it worked fine. When I run the query now, result has 95 rows. It shows the following error
---
A name contained an invalid character. Error processing resource
---
In notepad, the structure is not shown properly. It is shown as one continuos string, no separate lines.
Avatar of Anthony Perkins
>>Today morning, I tried when there was only one line and it worked fine. When I run the query now, result has 95 rows. It shows the following error<<
As alluded previously, it will be fine when only one row meets the condition, anything more and it will produce an Xml document that is not well-formed (it has no parent tag).

>>In notepad, the structure is not shown properly. It is shown as one continuos string, no separate lines. <<
Xml does not need "separate lines" for it to be well-formed or valid.
The error "a name contained an invalid character" sounds like it is an XML parsing error again, not the result of the BCP command.

Actually I suspect you are probably getting this error when selecting the XML in SQLServerManagement Studio, after you have run the FOR AUTO statement?

This is likely to be due to the column widths you have setup in SSMS.

See this link for more info:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=42573

We need to try and strip out all the other errors, and just focus on the error that BCP is producing please.

Thanks,
Avatar of MPI_IT

ASKER

I don't get any error while running in SQL server Managemet Studio using
exec sp_Ap ( which has select statement with for xml auto, root("Iss"),elements).
Test post as having trouble posting.
Ok so run the full thing again with its BCP and cmdshell wrapper and then open the file produced a non-XML aware editor like Wordpad or Ultraedit.

Does it look complete?
ASKER CERTIFIED SOLUTION
Avatar of MPI_IT
MPI_IT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The original issue reported seems to have been solved, so I would respectfully suggest that I have earned points for my advice.