Solved

xml file from sql server using bcp

Posted on 2011-02-18
11
951 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 193
ISDATE() not working properly on my table? Any suggestions. 7 54
Query to return total 6 26
Addition to SQL for dynamic fields 6 63
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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