欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp下将数据库中的信息存储至XML文件中

程序员文章站 2023-11-17 21:06:28
save.asp <% ' constan...
save.asp
<!-- #include file="adovbs.inc" -->
<%
' constants file included above.
' 如果文件存在则删除
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 connection
dim rstxml  ' ado recordset
'创建数据连接对象
set cnnxml = server.createobject("adodb.connection")
' 这是连接access数据库的例子:
'cnnxml.open "provider=microsoft.jet.oledb.4.0;data source=" _
' & server.mappath("db_scratch.mdb") & ";"
' 下面以sqlserver为例子讲解:
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
%>