save.asp
<!--#includefile="adovbs.inc"-->
<%
'Constantsfileincludedabove.
'If the file exists, delete it
DimobjFSO
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
IfobjFSO.FileExists(Server.MapPath("db_xml.xml")) Then
objFSO.DeleteFileServer.MapPath("db_xml.xml")
EndIF
SetobjFSO=Nothing
'Variable declaration
DimcnnXML'ADOconnection
DimrstXML'ADOrecordset
'Create a data connection object
SetcnnXML=Server.CreateObject("ADODB.Connection")
'This is an example of connecting to the access database:
'cnnXML.Open"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="_
'&Server.MapPath("db_scratch.mdb")&";"
'The following is an example to explain:
cnnXML.Open"Provider=SQLOLEDB;DataSource=10.2.1.214;"_
&"InitialCatalog=samples;UserId=samples;Password=password;"_
&"ConnectTimeout=15;NetworkLibrary=dbmssocn;"
SetrstXML=Server.CreateObject("ADODB.Recordset")
SetrstXML=cnnXML.Execute("SELECT*FROMscratchORDERBYid;")
Response.Write"<p>SavingdataasXML...</p>"&vbCrLf
'Save to xml format.
rstXML.SaveServer.MapPath("db_xml.xml"),adPersistXML
'Close the object and release the resource
rstXML.Close
SetrstXML=Nothing
cnnXML.Close
SetcnnXML=Nothing
Response.Write"<p>XMLfilewriten...</p>"&vbCrLf
Response.Write"<p>Click<ahref=""db_xml.xml"">here</a>toviewthefile.</p>"&vbCrLf
%>