我正在尝试使用XML Bulk Load(sql server 2008)。我几乎在那里,但我认为我的架构文件是错误的。我得到的错误是:
这就是我所拥有的:
SQL表结构:
架构文件:
<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:xml:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
<ElementType name="weight" dt:type="string" />
<ElementType name="fwd" dt:type="float" />
<ElementType name="aft" dt:type="float" />
<ElementType name="CGs" sql:is-constant="1">
<element type="gross" />
</ElementType>
<ElementType name="gross" sql:relation="tblCGLimits">
<element type="weight" sql:field="weight" />
<element type="fwd" sql:field="fwd" />
<element type="aft" sql:field="aft" />
</ElementType>
</Schema>
XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<CGs>
<gross weight="8000">
<fwd>196.5</fwd>
<aft>208.88162</aft>
</gross>
<gross weight="8001">
<fwd>196.495</fwd>
<aft>208.8825148</aft>
</gross>
<gross weight="8002">
<fwd>196.49</fwd>
<aft>208.8834096</aft>
</gross>
</CGs>
我正在使用的VBScript:
Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad")
objBL.ConnectionString = "provider=SQLOLEDB.1;data source=MyServer;database=MyDB;uid=MyUser;pwd=MyPW"
objBL.ErrorLogFile = "c:\XMLError.log"
objBL.Execute "c:\Schema.xml", "c:\CGLimits.xml"
Set objBL = Nothing
答案 0 :(得分:2)
您的XSD文件指定权重值是元素,而不是属性,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<CGs>
<gross>
<weight>8000</weight>
<fwd>196.5</fwd>
<aft>208.88162</aft>
</gross>
<gross>
<weight>8001</weight>
<fwd>196.495</fwd>
<aft>208.8825148</aft>
</gross>
<gross>
<weight>8002</weight>
<fwd>196.49</fwd>
<aft>208.8834096</aft>
</gross>
</CGs>
要更正此问题,请更改
<element type="weight" sql:field="weight"/>
到
<attribute type="weight" sql:field="weight"/>
在XSD文件中。