home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / ASP / ado_to_xml.asp < prev    next >
Encoding:
Text File  |  2001-06-08  |  2.1 KB  |  60 lines

  1. <%
  2. '*******************************************************
  3. '*     ASP 101 Sample Code - http://www.asp101.com     *
  4. '*                                                     *
  5. '*   This code is made available as a service to our   *
  6. '*      visitors and is provided strictly for the      *
  7. '*               purpose of illustration.              *
  8. '*                                                     *
  9. '* Please direct all inquiries to webmaster@asp101.com *
  10. '*******************************************************
  11. %>
  12.  
  13. <!-- #include file="adovbs.inc" -->
  14. <%
  15. ' Constants file included above.
  16.  
  17. ' Delete existing file
  18. Dim objFSO
  19. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  20. If objFSO.FileExists(Server.MapPath("db_xml.xml")) Then
  21.     objFSO.DeleteFile Server.MapPath("db_xml.xml")
  22. End IF
  23. Set objFSO = Nothing
  24.  
  25. ' Declare our variables... always good practice.
  26. Dim cnnXML  ' ADO connection
  27. Dim rstXML  ' ADO recordset
  28.  
  29. ' Create an ADO Connection to connect to the scratch database.
  30. ' We're using OLE DB but you could just as easily use ODBC or a DSN.
  31. Set cnnXML = Server.CreateObject("ADODB.Connection")
  32.  
  33. ' This line is for the Access sample database:
  34. 'cnnXML.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
  35. '    & Server.MapPath("db_scratch.mdb") & ";"
  36.  
  37. ' We're actually using our site-wide SQL Server connection:
  38. cnnXML.Open Application("SQLConnString"), Application("SQLUsername"), _
  39.     Application("SQLPassword")
  40.  
  41. ' Execute a query using the connection object.  It automatically
  42. ' creates and returns a recordset which we store in our variable.
  43. Set rstXML = Server.CreateObject("ADODB.Recordset")
  44. Set rstXML = cnnXML.Execute("SELECT * FROM scratch ORDER BY id;")
  45.  
  46. Response.Write "Saving data as XML...<br>" & vbCrLf
  47.  
  48. ' Save the file to XML format.
  49. rstXML.Save Server.MapPath("db_xml.xml"), adPersistXML
  50.  
  51. ' Close our recordset and connection and dispose of the objects
  52. rstXML.Close
  53. Set rstXML = Nothing
  54. cnnXML.Close
  55. Set cnnXML = Nothing
  56.  
  57. Response.Write "XML file written...<br>" & vbCrLf
  58. Response.Write "Click <a href=""db_xml.xml"">here</a> to view the file.<br>" & vbCrLf
  59. %>
  60.