扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<%@ Page Language="C#" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
TextBox1.Text = "PROVIDER=SQLOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;";
Label1.Text = "";
}
}
void CreateXml(object sender, EventArgs e) {
OleDbConnection dataConn = new OleDbConnection(TextBox1.Text);
Uri Path = Request.Url;
String ServerUrl = Path.ToString();
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") +1 );
try {
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>" ;
dataConn.Open();
DataTable schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
for(int i = 0; i < schemaTable.Rows.Count; i++){
OleDbDataAdapter dbAdapter= new OleDbDataAdapter("select * from [" + schemaTable.Rows[i].ItemArray[2].ToString() + "]",dataConn);
DataSet tableData = new DataSet();
dbAdapter.Fill(tableData,schemaTable.Rows[i].ItemArray[2].ToString());
tableData.WriteXml(HttpContext.Current.Server.MapPath(schemaTable.Rows[i].ItemArray[2].ToString() + ".xml"));
Literal1.Text = Literal1.Text + "<a href=http://www.ddvip.com/web/xml/index2/''" + ServerUrl + schemaTable.Rows[i].ItemArray[2].ToString() + ".xml''>";
Literal1.Text = Literal1.Text + schemaTable.Rows[i].ItemArray[2].ToString() + ".xml</a><br/>";
}
}
catch(Exception ex) {
Label1.Text = ex.Message.ToString();
}
finally {
dataConn.Close();
}
}
</script>
<html>
<head>
<title>leDb2XML:数据库转换成XML文件例子</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h2><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font>
</h2>
</center>
<form runat="server" ID="Form1">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" onclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</html>
VB.NET版本:[测试]
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System" %>
<%@ Page Language="VB" %>
<HTML>
<HEAD>
<title>leDb2XML:数据库转换成XML文件例子</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
''TextBox1.Text = "Provider=SqlOLEDB; Data Source=.; Initial Catalog=pubs;User ID=sa;Password=;"
Label1.Text = ""
TextBox1.Text = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Test.mdb")
End If
End Sub
Sub CreateXml(sender As Object, e As EventArgs)
Dim dataConn As New OleDbConnection(TextBox1.Text)
Dim Path As Uri = Request.Url
Dim ServerUrl As String = Path.ToString()
ServerUrl = ServerUrl.Substring(0,ServerUrl.LastIndexOf("/") + 1 )
Try
Literal1.Text = "已经在你的相同目录下创建了一下文件:<br/>"
dataConn.Open()
Dim schemaTable As DataTable
schemaTable = dataConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim i As Integer
For i = 0 To schemaTable.Rows.Count - 1
Dim dbAdapter As New OleDbDataAdapter("select * from [" + schemaTable.Rows(i).ItemArray(2).ToString() + "]", dataConn)
Dim tableData As New DataSet()
dbAdapter.Fill(tableData, schemaTable.Rows(i).ItemArray(2).ToString())
tableData.WriteXml(HttpContext.Current.Server.MapPath((schemaTable.Rows(i).ItemArray(2).ToString() + ".xml")))
Literal1.Text = Literal1.Text + "<a href=http://www.ddvip.com/web/xml/index2/''" + ServerUrl + schemaTable.Rows(i).ItemArray(2).ToString() + ".xml''>"
Literal1.Text = Literal1.Text + schemaTable.Rows(i).ItemArray(2).ToString() + ".xml</a><br/>"
Next i
Catch ex As Exception
Label1.Text = ex.Message.ToString()
Finally
dataConn.Close()
End Try
End Sub
</script>
</HEAD>
<body bgcolor="#ffffff">
<h2 align=center><font face="宋体">OleDb2XML:数据库转换成XML文件例子</font></h2>
<form runat="server" ID="Form1">
<font face="宋体">
<p align="center">请输入OleDb连接字符串,然后点“生成XML文件”按钮。</p>
<p align="center">
<asp:TextBox id="TextBox1" runat="server" Width="600"></asp:TextBox>
</p>
<p align="center">
<asp:Button id="Button1" onclick="CreateXml" runat="server" Text="生成XML文件"></asp:Button>
</p>
<p align="center">
<asp:Label id="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</p>
<p align="center">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</p>
</font>
</form>
</body>
</HTML>
对于数据量大的数据库,处理可能会需要更多的时间,因此有可能需要更改machine.config文件中processModel的responseDeadlockInterval 属性,比如为5分钟,默认为3分钟。
<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseRestartDeadlockInterval="00:09:00"
responseDeadlockInterval="00:05:00" default is 00:03:00
maxWorkerThreads="25"
maxIoThreads="25" />
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者