Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

xml file from sql server using bcp

Posted on 2011-02-18
11
Medium Priority
?
970 Views
Last Modified: 2012-05-11
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...

-----------------------
0
Comment
Question by:MPI_IT
  • 5
  • 3
9 Comments
 
LVL 7

Expert Comment

by:lozzamoore
ID: 34944068
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,
0
 

Author Comment

by:MPI_IT
ID: 34945666
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.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34949037
>>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.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 7

Expert Comment

by:lozzamoore
ID: 34950139
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,
0
 

Author Comment

by:MPI_IT
ID: 34951976
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).
0
 
LVL 7

Expert Comment

by:lozzamoore
ID: 34959363
Test post as having trouble posting.
0
 
LVL 7

Expert Comment

by:lozzamoore
ID: 34959370
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?
0
 

Accepted Solution

by:
MPI_IT earned 0 total points
ID: 34997779
When I used Type with xml auto, errors are gone and it looks like as valid xml file. I won't know it for sure until it is tested at a customer's computer.I want to close this case for now, and reopen if needed. Thanks for all the help.
0
 
LVL 7

Expert Comment

by:lozzamoore
ID: 35138879
The original issue reported seems to have been solved, so I would respectfully suggest that I have earned points for my advice.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question