<!-- #include file="adovbs.inc" -->
<%
' 刪除已經存在的文件
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath("db_xml.XML")) Then
objFSO.DeleteFile Server.MapPath("db_xml.XML")
End IF
Set objFSO = Nothing
' 定義變量,很好的習慣
Dim cnnXML ' ADO 連接
Dim rstXML ' ADO 記錄集
Set cnnXML = Server.CreateObject("ADODB.Connection")
cnnXML.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;PassWord=passWord;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
Set rstXML = Server.CreateObject("ADODB.Recordset")
Set rstXML = cnnXML.Execute("SELECT * FROM scratch ORDER BY id;")
Response.Write "<p>Saving data as XML...</p>" & vbCrLf
' 保存XML各式的文件.
rstXML.Save Server.MapPath("db_xml.xml"), adPersistXML
' 關閉數據庫連接,釋放對象
rstXML.Close
Set rstXML = Nothing
cnnXML.Close
Set cnnXML = Nothing
Response.Write "<p>XML file written...</p>" & vbCrLf
Response.Write "<p>Click <a href=""db_xml.XML"">here</a> to vIEw the file.</p>" & vbCrLf
%>