Generating XML from SQL Database
This sample shows how you can obtain a Dataset from (in this case) a SQL Server database, and then write it out to an XML Document. As an Extra Added Bonus(tm), it can show you how to write the schema as well.
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Generating XML from SQL Database
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
S VKPosted Nov 18, 2010, 5:17 AM
i am creating xml file frm databse as above but the output i get is not in the proper format as nodes, elemnts & sub elemnts needes to be grouped morre how can it be done thr' code
razel guinideditedPosted Jan 12, 2006, 12:30 AMEdited Mar 7, 2006, 1:33 PM
hello I have seen your article titled "<!--StartFragment --> Generating XML from SQL Database by Shivani Jul 01, 2003 " I was very delighted because this is really what i am looking for. I am trying to use xml in my program that has to retrieve thousands of records. I am currently putting these values in a session variable but i think i have to persist it in an xml rather than in a session variable for performance purposes. This is my code based on your code. Dim ObjConn As New SqlConnection(ConfigurationSettings.AppSettings("strConnection")) Dim ObjAdapter = New SqlDataAdapter(String.Format("strProcTemp '{0}'", "12"), ObjConn) Dim ObjDataset As New DataSet ObjAdapter.Fill(ObjDataset, "XXX") Dim ObjDataTable As DataTable = ObjDataset.Tables("XXX") Dim myFs As FileStream = Nothing myFs = New FileStream("D:\myXML" + ".xml", FileMode.OpenOrCreate, FileAccess.Write) ObjDataset.WriteXml(myFs) myFs.Close() This is the error generated. Access to the path "D:\myXML.xml" is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path "D:\myXML.xml" is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. Source Error: Line 46: Line 47: Dim myFs As FileStream = Nothing Line 48: myFs = New FileStream("D:\myXML" + ".xml", FileMode.OpenOrCreate, FileAccess.Write) Line 49: ' Apply the WriteXml method to write an XML document Line 50: ObjDataset.WriteXml(myFs) Could you please tell me or better yet show me what my code is doing wrong? More power to you!