以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML 与 数据库 』  (http://bbs.xml.org.cn/list.asp?boardid=17)
----  如何将XML文件导出成SQL数据库中的数据?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=17&rootid=&id=9663)


--  作者:init.ora
--  发布时间:9/1/2004 11:05:00 AM

--  如何将XML文件导出成SQL数据库中的数据?
msdn 里面的內容﹕

A. Bulk loading XML in a table
The following script, written in the Microsoft Visual Basic® Scripting Edition (VBScript), loads an XML document into a table.

set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.2.0")
objBL.ConnectionString = "provider=SQLOLEDB.1;data source=localhost;database=Northwind;uid=UserName;pwd=UserPassword"
objBL.ErrorLogFile = "c:\error.log"
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing

1.Create this table:
CREATE TABLE Cust(CustomerID  int PRIMARY KEY,
                       CompanyName varchar(20),
                  City        varchar(20))
GO

2。Create a file in Notepad, and save it as SampleSchema.xml. To this file, add the following XSD schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">

  <xsd:element name="Customers" sql:relation="Cust" >
   <xsd:complexType>
     <xsd:sequence>
       <xsd:element name="CustomerID"  type="xsd:integer" />
       <xsd:element name="CompanyName" type="xsd:string" />
       <xsd:element name="City"        type="xsd:string" />
     </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

3.Create a file in Notepad, and save it as SampleXMLData.xml. To this file, add the following XML document:
<ROOT>
  <Customers>
    <CustomerID>1111</CustomerID>
    <CompanyName>Sean Chai</CompanyName>
    <City>NY</City>
  </Customers>
  <Customers>
    <CustomerID>1112</CustomerID>
    <CompanyName>Tom Johnston</CompanyName>
     <City>LA</City>
  </Customers>
  <Customers>
    <CustomerID>1113</CustomerID>
    <CompanyName>Institute of Art</CompanyName>
  </Customers>
</ROOT>

4.Create a file in Notepad, and save it as BLoad.vbs. To this file, add the VBScript code that is provided in this example. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that are specified as parameters to the Execute method.


5.Execute the VBScript code. XML Bulk Load loads the XML into the Cust table.

偶運行出錯如下﹕請指教

Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Cannot create ActiveX component.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Cannot create ActiveX component.

Source Error:


Line 5:  sub page_load (sender as object, e as eventargs)
Line 6:  dim objbl
Line 7:   objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.2.0")
Line 8:  objBL.ConnectionString = "provider=SQLOLEDB.1;data source=localhost;database=Northwind;uid=UserName;pwd=UserPassword"
Line 9:  objBL.ErrorLogFile = "c:\error.log"

Source File: C:\Inetpub\wwwroot\WebApplication2\test.aspx    Line: 7

Stack Trace:


[Exception: Cannot create ActiveX component.]
   Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
   ASP.test_aspx.page_load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication2\test.aspx:7
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()



W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
3,781.250ms