SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : XML Technologies :

Previous DiscussionNext Discussion
 Propagate Identity Column Multiple Tables Using SQLXMLBulkLoad

Hi All,

It's been a long time since I was here. Hope you are all well and making a good living.

I have hit a bit of brick wall with some XML / SQL Server 2000 issue and wondered if there were any "Experts" out there that could provide that nugget of information to help me solve a problem.

Here is some background.....

I stumbled across your entry "Propagating identity values in multiple tables using SQLXMLBulkLoad" (http://blogs.msdn.com/monicafrintu/archive/2007/06/14/propagating-identity-values-in-multiple-tables-using-sqlxmlbulkload.aspx)

And I thought it was the answer to my prayers.

Sadly, I cannot get it to work when there is a slightly more complicated example than the one shown.

No matter what I try I get the failure :-

CREATE DEFAULT must be the first statement in a query batch

My XML Structure is as follows :-

<?xml version="1.0" encoding="ISO-8859-1" ?>
<calls xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="data.xsd">
<call>
<interface_process_id>1508</interface_process_id>
    <mode><![CDATA[NEW]]></mode>
    <job><![CDATA[90000001]]></job>
    <visit><![CDATA[2008-02-18]]></visit>
    <fru><![CDATA[CDAM]]></fru>
    <allday><![CDATA[ALL DAY]]></allday>
    <commentscus><![CDATA[TEST]]></commentscus>
    <commentseng><![CDATA[]]></commentseng>
    <bib><![CDATA[N]]></bib>
    <removestb><![CDATA[N]]></removestb>
    <fasttrack><![CDATA[N]]></fasttrack>
    <stbcount><![CDATA[1]]></stbcount>
    <diaryslots><![CDATA[85.0]]></diaryslots>
    <engineer>
        <id><![CDATA[CDA1001]]></id>
    </engineer>
    <customer>
        <id><![CDATA[59302678]]></id>
        <subscriber><![CDATA[240000000135]]></subscriber>
        <vip><![CDATA[N]]></vip>
        <title><![CDATA[MR]]></title>
        <initials><![CDATA[M]]></initials>
        <surname><![CDATA[XXXXXXX]]></surname>
        <street><![CDATA[XXXXXXXXXXX]]></street>
        <city><![CDATA[XXXXXXXXXXXXXXXXXXX]]></city>
        <county><![CDATA[XXXXXXXXXXXXXXXXXXXXX]]></county>
        <phonehome><![CDATA[0000000000000000]]></phonehome>
        <phonework><![CDATA[]]></phonework>
        <postcode><![CDATA[XXX XXX]]></postcode>
    </customer>
    <contact>
        <name><![CDATA[SIDDALL]]></name>
        <phone><![CDATA[01501744130]]></phone>
        <salutation><![CDATA[MR]]></salutation>
    </contact>
    <contract>
        <name><![CDATA[DIX002]]></name>
        <description><![CDATA[NS - Dixon Stores Group]]></description>
    </contract>
    <service>
        <name><![CDATA[ID1]]></name>
        <description><![CDATA[Standard Digital Install & Phone Link]]></description>
    </service>
    <product>
        <name><![CDATA[AMS100Z2]]></name>
        <description><![CDATA[PRODUCT 1]]></description>
    </product>
    <cost>
        <total><![CDATA[ 117.50]]></total>
        <prepaid><![CDATA[ 0.00]]></prepaid>
        <outstanding><![CDATA[ 117.50]]></outstanding>
    </cost>
</call>
<visitHistorys>
    <visitHistory>
 <visitNumber>30068347</visitNumber>
 <visitDate>2007-11-01 00:00:00.0 GMT</visitDate>
 <visitType>Install</visitType>
 <engineerID>80100</engineerID>
 <visitStatus>CP</visitStatus>
 <statusCodes> 
     <statusCode> 
  <type>Cause</type>
  <code>38</code>
  <desc>Broken Connectors</desc>          
     </statusCode> 
 </statusCodes> 
    </visitHistory>
    <contactDetails>
 <contactNumber>
     <description>XXXXXXXXXX</description>
     <number>XXXXXXXXXX</number>
 </contactNumber>
    </contactDetails>
    <maxNoVisit>6</maxNoVisit>
    <timePeriodMonths>12</timePeriodMonths>
</visitHistorys>
</calls>


And have devised an XSD :-

 

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns="http://tempuri.org/XMLSchema.xsd"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
 <xsd:annotation>
  <xsd:appinfo>
   <sql:relationship name="History"
            parent="tbl_Job_Raw_XML"
            child="tbl_Job_Raw_XML_History"
            parent-key="Job_Raw_XML_Id"
            child-key="Job_Raw_XML_Id" />
   <sql:relationship name="Visit"
            parent="tbl_Job_Raw_XML_History"
            child="tbl_Job_Raw_XML_Visit"
            parent-key="Job_Raw_XML_History_Id"
            child-key="Job_Raw_XML_History_Id" />
   <sql:relationship name="Status"
            parent="tbl_Job_Raw_XML_Visit"
            child="tbl_Job_Raw_XML_Status"
            parent-key="Job_Raw_XML_Visit_Id"
            child-key="Job_Raw_XML_Visit_Id" />
   <sql:relationship name="Contact"
            parent="tbl_Job_Raw_XML_History"
            child="tbl_Job_Raw_XML_Contact"
            parent-key="Job_Raw_XML_History_Id"
            child-key="Job_Raw_XML_History_Id" />
  </xsd:appinfo>
 </xsd:annotation>
 <xsd:element name="calls" sql:is-constant="1">
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="call" sql:relation="tbl_Job_Raw_XML">
     <xsd:complexType>
      <xsd:sequence>
       <xsd:element name="interface_process_id" type="xsd:integer" sql:field="Interface_Process_Id" minOccurs="1" maxOccurs="1" />
       <xsd:element name="mode" type="xsd:token" sql:field="Mode" minOccurs="1" maxOccurs="1" />
       <xsd:element name="fru" type="xsd:token" sql:field="FRU" />
       <xsd:element name="job" type="xsd:token" sql:field="Job_No" />
       <xsd:element name="reference" type="xsd:token" sql:field="Job_Reference" />
       <xsd:element name="visit" type="xsd:token" sql:field="Job_Date" />
       <xsd:element name="allday" type="xsd:token" sql:field="All_Day" />
       <xsd:element name="commentscus" type="xsd:token" sql:field="Comments_Customer" />
       <xsd:element name="commentseng" type="xsd:token" sql:field="Comments_Resource" />
       <xsd:element name="bib" type="xsd:token" sql:field="BIB_Ind" />
       <xsd:element name="removestb" type="xsd:token" sql:field="Remove_STB_Ind" />
       <xsd:element name="fasttrack" type="xsd:token" sql:field="Fast_Track_Ind" />
       <xsd:element name="sit" type="xsd:token" sql:field="SIT_Ind" />
       <xsd:element name="lip" type="xsd:token" sql:field="LIP_Ind" />
       <xsd:element name="stbcount" type="xsd:token" sql:field="STB_Count" />
       <xsd:element name="diaryslots" type="xsd:token" sql:field="Diary_Slots" />
       <xsd:element name="engineer" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="id" type="xsd:token" sql:field="Engineer_Id" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="customer" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="id" type="xsd:token" sql:field="SKY_Customer_Id" />
          <xsd:element name="subscriber" type="xsd:token" sql:field="SKY_Subscriber_No" />
          <xsd:element name="vip" type="xsd:token" sql:field="Customer_VIP" />
          <xsd:element name="title" type="xsd:token" sql:field="Customer_Title" />
          <xsd:element name="initials" type="xsd:token" sql:field="Customer_Initials" />
          <xsd:element name="surname" type="xsd:token" sql:field="Customer_Surname" />
          <xsd:element name="street" type="xsd:token" sql:field="Customer_Street" />
          <xsd:element name="city" type="xsd:token" sql:field="Customer_City" />
          <xsd:element name="county" type="xsd:token" sql:field="Customer_County" />
          <xsd:element name="phonehome" type="xsd:token" sql:field="Customer_Phone_Home" />
          <xsd:element name="phonework" type="xsd:token" sql:field="Customer_Phone_Work" />
          <xsd:element name="postcode" type="xsd:token" sql:field="Customer_Post_Code" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="contact" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="name" type="xsd:token" sql:field="Customer_Contact_Name" />
          <xsd:element name="phone" type="xsd:token" sql:field="Customer_Contact_Phone" />
          <xsd:element name="salutation" type="xsd:token" sql:field="Customer_Contact_Salutation" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="contract" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="name" type="xsd:token" sql:field="Contract_Name" />
          <xsd:element name="description" type="xsd:token" sql:field="Contract_Descr" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="service" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="name" type="xsd:token" sql:field="Service_Name" />
          <xsd:element name="description" type="xsd:token" sql:field="Service_Descr" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="product" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="name" type="xsd:token" sql:field="Product_Name" />
          <xsd:element name="description" type="xsd:token" sql:field="Product_Descr" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="warranty" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="reference" type="xsd:token" sql:field="Warranty_Reference" />
          <xsd:element name="date" type="xsd:token" sql:field="Warranty_Date" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="fault" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="name" type="xsd:token" sql:field="Fault_Name" />
          <xsd:element name="description" type="xsd:token" sql:field="Fault_Descr" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="history" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="engineerOrig" sql:is-constant="1">
           <xsd:complexType>
            <xsd:sequence>
             <xsd:element name="id" type="xsd:token" sql:field="Engineer_Orig_Id" />
             <xsd:element name="name" type="xsd:token" sql:field="Engineer_Orig_Name" />
            </xsd:sequence>
           </xsd:complexType>
          </xsd:element>
          <xsd:element name="engineerLast" sql:is-constant="1">
           <xsd:complexType>
            <xsd:sequence>
             <xsd:element name="id" type="xsd:token" sql:field="Engineer_Last_Id" />
             <xsd:element name="name" type="xsd:token" sql:field="Engineer_Last_Name" />
             <xsd:element name="type" type="xsd:token" sql:field="Engineer_Last_Type" />
            </xsd:sequence>
           </xsd:complexType>
          </xsd:element>
          <xsd:element name="jobcount" type="xsd:token" sql:field="Job_Count" />
          <xsd:element name="installdate" type="xsd:token" sql:field="Installation_Date" />
          <xsd:element name="lastdate" type="xsd:token" sql:field="Last_Date" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="enquiry" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="enqreference" type="xsd:token" sql:field="Enquiry_Ref" />
          <xsd:element name="enqreason" type="xsd:token" sql:field="Enquiry_Reason" />
          <xsd:element name="enqsreason" type="xsd:token" sql:field="Enquiry_Sub_Reason" />
          <xsd:element name="enqdescription" type="xsd:token" sql:field="Enquiry_Descr" />
          <xsd:element name="enqcomments1" type="xsd:token" sql:field="Enquiry_Comments_1" />
          <xsd:element name="enqcomments2" type="xsd:token" sql:field="Enquiry_Comments_2" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="cost" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="total" type="xsd:token" sql:field="Cost_Total" />
          <xsd:element name="prepaid" type="xsd:token" sql:field="Cost_Pre_Paid" />
          <xsd:element name="outstanding" type="xsd:token" sql:field="Cost_Outstanding" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="summary" sql:is-constant="1">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="count" type="xsd:token" sql:field="Call_Count" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="cancel_code" type="xsd:token" sql:field="Cancel_Code" />
       <xsd:element name="cancel_reason" type="xsd:token" sql:field="Cancel_Reason" />

       <xsd:element name="visitHistorys" sql:relation="tbl_Job_Raw_XML_History" sql:relationship="History">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="visitHistory" sql:relation="tbl_Job_Raw_XML_Visit" sql:relationship="Visit">
           <xsd:complexType>
            <xsd:sequence>
             <xsd:element name="visitNumber" type="xsd:token" sql:field="Visit_Number" />
             <xsd:element name="visitDate" type="xsd:date" sql:field="Visit_Date" />
             <xsd:element name="visitType" type="xsd:token" sql:field="Visit_Type" />
             <xsd:element name="engineerID" type="xsd:token" sql:field="Engineer_Id" />
             <xsd:element name="visitStatus" type="xsd:token" sql:field="Visit_Status" />

             <xsd:element name="statusCodes" sql:is-constant="1">
              <xsd:complexType>
               <xsd:sequence>
                <xsd:element name="statusCode" sql:relation="tbl_Job_Raw_XML_Status" sql:relationship="Status">
                 <xsd:complexType>
                  <xsd:sequence>
                   <xsd:element name="type" type="xsd:token" sql:field="Type" />
                   <xsd:element name="code" type="xsd:token" sql:field="Code" />
                   <xsd:element name="desc" type="xsd:token" sql:field="Desc" />
                  </xsd:sequence>
                 </xsd:complexType>
                </xsd:element>
               </xsd:sequence>
              </xsd:complexType>
             </xsd:element>

            </xsd:sequence>
           </xsd:complexType>
          </xsd:element>

          <xsd:element name="contactDetails" sql:is-constant="1">
           <xsd:complexType>
            <xsd:sequence>
             <xsd:element name="contactNumber" sql:relation="tbl_Job_Raw_XML_Contact" sql:relationship="Contact">
              <xsd:complexType>
               <xsd:sequence>
                <xsd:element name="description" type="xsd:token" sql:field="Description" />
                <xsd:element name="number" type="xsd:token" sql:field="Number" />
               </xsd:sequence>
              </xsd:complexType>
             </xsd:element>
            </xsd:sequence>
           </xsd:complexType>
          </xsd:element>

          <xsd:element name="maxNoVisit" type="xsd:token" sql:field="Max_No_Visit" />
          <xsd:element name="timePeriodMonths" type="xsd:token" sql:field="Time_Period_Months" />

         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>

      </xsd:sequence>
     </xsd:complexType>
    </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

In "English", I have 4 tables :-

tbl_Job_Raw_XML
tbl_Job_Raw_XML_History
tbl_Job_Raw_XML_Visit
tbl_Job_Raw_XML_Status
tbl_Job_Raw_XML_Contact

tbl_Job_Raw_XML_History is a child of tbl_Job_Raw_XML
tbl_Job_Raw_XML_Visit is a child of tbl_Job_Raw_XML_History
tbl_Job_Raw_XML_Status is a child of tbl_Job_Raw_XML_Visit
tbl_Job_Raw_XML_Contact is a child of tbl_Job_Raw_XML_History

(NOT MY DESIGN!)

I was praying that by following the example I could extend it to cater with this more complicated example.


Just in case this was too complicated, I changed the XML and the XSD to only refer to 2 tables :-

tbl_Job_Raw_XML
tbl_Job_Raw_XML_History


And no matter what I do, I cannot get the thing to work.

What I am expecting is to propogate the Identity Column from tbl_Job_Raw_XML down onto tbl_Job_Raw_XML_History. This just does not happen.


If I am doing something wrong, or the SQLXMLBulkLoad'er cannot support this complexity, I would very much appreciate your guidance.

So that you know, I am using :-

Windows 2000 SP4
SQL Server 2000 SP3
SQLXML 4.0


Sorry this is such a long post!

Yours.....

Simple Simon

Started By swjs on Feb 18, 2008 at 9:46:24 AM

12 Response(s) | Reply

Earlier Replies | Replies 6 to 12 of 12 | Later Replies
Goto Page: 2 1
ChrisRickard on Feb 18, 2008 at 3:39:35 PM (# 6)

When do you get the error?


swjs on Feb 19, 2008 at 1:42:30 AM (# 7)

Hi Chris,

I get the error during the .Execute on the SQLXMLBulkLoad object. Here is the SQL Server 2000 DTS VBScript :-

Function Bulk_Load_XML_File(s_Parm_XSD_File_Name, s_Parm_File_Name, s_Parm_Process_Message)

 Dim objXBulkLoad

 Dim b_Error_Encountered
 
 '#
 '### Assume No Errors will be encountered
 '#
 
 b_Error_Encountered = False
 
 '#
 '### Instantiate the XML Bulk Load Object
 '#

 Set objXBulkLoad = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.4.0")

 '#
 '### Apply the Database connection string
 '#

 objXBulkLoad.ConnectionString = "PROVIDER=SQLOLEDB.1;SERVER=.;UID=whatever;PWD=yeahright;DATABASE=BIG_DB;"

 '#
 '### Force Identity Column to be maintained
 '#

 objXBulkLoad.KeepIdentity = False

 '#
 '### Force Transaction
 '#

 objXBulkLoad.Transaction = True

'#SWJS# Only allow this property to be set if the XML
'#SWJS# document does not contain a root element.
'#SWJS# However, before changing, make sure the xsd is updated accordingly.
'#SWJS#
'#SWJS# objXBulkLoad.XMLFragment = True

 '#
 '### Identify the Error Log File
 '#

 objXBulkLoad.ErrorLogFile = DTSGlobalVariables("gs_XMLBulkLoad_Log_File_Name").Value

 '#
 '### Identify the Temporary File Path
 '#

 objXBulkLoad.TempFilePath = DTSGlobalVariables("gs_XMLBulkLoad_Temp_File_Path").Value


 '#
 '### Execute the Bulk Load for the XML Document
 '#

 On Error Resume Next
 
 objXBulkLoad.Execute s_Parm_XSD_File_Name, s_Parm_File_Name  '<== FAILING STATEMENT, BUT CAUGHT!

 If Err.number <> 0 Then
 
  s_Parm_Process_Message = s_Parm_Process_Message & Now() & " - " & "Fatal Error Encountered in Bulk_Load_XML_File processing File : " & s_Parm_File_Name & " - Error Details : " & Err.number & " - " & Err.Description & vbCrLf

  b_Error_Encountered = True
  
 End If
 
 On Error Goto 0
 
 '#
 '### Return Boolean Status
 '#

 Bulk_Load_XML_File = Not b_Error_Encountered

End Function

The error I get is "CREATE DEFAULT must be the first statement in a query batch" and it is repeated several times.

It is an absolute bugger because I have found 2 very conflicting Microsoft references :-

1. This says it should work :-

http://msdn2.microsoft.com/en-us/library/aa225730(SQL.80).aspx

2. This catagorically says it won't :-

http://support.microsoft.com/kb/330582

I have found numerous examples indicating it will work with the automatic creation of IDENTITY Values. I have found lots of examples where you supply the ID's in the XML.

Unfortunately I must use automatic creation of IDENTITY Values as I am being sent the data from another company.

I am thinking that there is something wrong with the XSD. However, when I amend to make it a very simple 2 level structure, it still does not work.

Strangely, if I code inverse="true" on the sql:relationship it will create the entry in the child table, however it does not populate the Identity column value from the Parent.

I'm at my wits end with this one, coz the alternative is I have to hand craft, which I can do, but it is not as elegant and requires considerably more time and effort!

Many thanks Chris.

Kind Regards...

Simon.


ChrisRickard on Feb 19, 2008 at 11:35:20 AM (# 8)

This is certainly something I'd have to do "hands on". If you can prepare en entire micro-database complete with tables, data, and DTS package that shows this behavior I'd have a lot more to work with. The smaller the better. You can send me the backup and I can get it up and running locally.


swjs on Feb 20, 2008 at 10:00:46 AM (# 9)

Hi Chris,

I have now completely confused myself.

I have created a complete test harness as suggested.

tbl_Temp_Parent
tbl_Temp_Child
tbl_Temp_Grand_Child

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbl_Temp_Child]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbl_Temp_Child]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbl_Temp_Grand_Child]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbl_Temp_Grand_Child]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbl_Temp_Parent]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbl_Temp_Parent]
GO

CREATE TABLE [dbo].[tbl_Temp_Child] (
 [Parent_Id] [int] NOT NULL ,
 [Child_Id] [int] IDENTITY (1000, 1) NOT NULL ,
 [Child_Data] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Child_Group_Data] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[tbl_Temp_Grand_Child] (
 [Child_Id] [int] NOT NULL ,
 [Grand_Child_Id] [int] IDENTITY (1000, 1) NOT NULL ,
 [Grand_Child_Data] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[tbl_Temp_Parent] (
 [Parent_Id] [int] IDENTITY (1000, 1) NOT NULL ,
 [Parent_Data] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Parent_Group_Data] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

 

I have created the XSD that will allow data to be propogated with the Identity columns through all three tables :-

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns="http://tempuri.org/XMLSchema.xsd"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
 <xsd:annotation>
  <xsd:appinfo>
   <sql:relationship name="Children"
            parent="tbl_Temp_Parent"
            child="tbl_Temp_Child"
            parent-key="Parent_Id"
            child-key="Parent_Id" />
   <sql:relationship name="Grand_Children"
            parent="tbl_Temp_Child"
            child="tbl_Temp_Grand_Child"
            parent-key="Child_Id"
            child-key="Child_Id" />
  </xsd:appinfo>
 </xsd:annotation>
 <xsd:element name="Parents" sql:is-constant="true">
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="Parent" minOccurs="1" maxOccurs="unbounded" sql:relation="tbl_Temp_Parent">
     <xsd:complexType>
      <xsd:sequence>
       <xsd:element name="Parent_Data" type="xsd:token" sql:field="Parent_Data" />
       <xsd:element name="Parent_Group" sql:is-constant="true">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="Parent_Group_Data" type="xsd:token" sql:field="Parent_Group_Data" />
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       <xsd:element name="Childs" sql:is-constant="true">
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element name="Child" minOccurs="1" maxOccurs="unbounded"  sql:relation="tbl_Temp_Child" sql:relationship="Children">
           <xsd:complexType>
            <xsd:sequence>
             <xsd:element name="Child_Group" sql:is-constant="true">
              <xsd:complexType>
               <xsd:sequence>
                <xsd:element name="Child_Group_Data" type="xsd:token" sql:field="Child_Group_Data" />
               </xsd:sequence>
              </xsd:complexType>
             </xsd:element>
             <xsd:element name="Child_Data" type="xsd:token" sql:field="Child_Data"/>

             <xsd:element name="Grand_Childs" sql:is-constant="true">
              <xsd:complexType>
               <xsd:sequence>
                <xsd:element name="Grand_Child" minOccurs="1" maxOccurs="unbounded"  sql:relation="tbl_Temp_Grand_Child" sql:relationship="Grand_Children">
                 <xsd:complexType>
                  <xsd:sequence>
                   <xsd:element name="Grand_Child_Data" type="xsd:token" sql:field="Grand_Child_Data"/>
                  </xsd:sequence>
                 </xsd:complexType>
                </xsd:element>

               </xsd:sequence>
              </xsd:complexType>
             </xsd:element>

            </xsd:sequence>
           </xsd:complexType>
          </xsd:element>

         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
      </xsd:sequence>
     </xsd:complexType>
    </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

 

And here is some data that I attempted to load :-

<?xml version="1.0" encoding="ISO-8859-1" ?>
<Parents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="skytobusparts.xsd">
 <Parent>
  <Parent_Data><![CDATA[HELLO PARENT 1]]></Parent_Data>
  <Parent_Group>
   <Parent_Group_Data><![CDATA[HELLO PARENT GROUP DATA 1]]></Parent_Group_Data>
  </Parent_Group>
  <Childs>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 1.1]]></Child_Data>
       <Child_Group>
        <Child_Group_Data><![CDATA[HELLO CHILD GROUP DATA 1.1]]></Child_Group_Data>
       </Child_Group>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.1.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.1.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.1.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 1.2]]></Child_Data>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.2.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.2.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.2.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 1.3]]></Child_Data>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.3.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.3.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 1.3.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
  </Childs>
 </Parent>
 <Parent>
  <Parent_Data><![CDATA[HELLO PARENT 2]]></Parent_Data>
  <Childs>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 2.1]]></Child_Data>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.1.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.1.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.1.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 2.2]]></Child_Data>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.2.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.2.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.2.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
   <Child>
       <Child_Data><![CDATA[HELLO CHILD 2.3]]></Child_Data>
       <Grand_Childs>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.3.1]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.3.2]]></Grand_Child_Data>
    </Grand_Child>
    <Grand_Child>
        <Grand_Child_Data><![CDATA[HELLO GRAND CHILD 2.3.3]]></Grand_Child_Data>
    </Grand_Child>
       </Grand_Childs>
   </Child>
  </Childs>
 </Parent>
</Parents>

Guess what?

It all loads successfully and correctly propogates the IDENTITY Columns through to each of the subordinate tables.

I have tried with/without CDATA and it works each time.

As soon as I try to run with my real data, with the structure exactly the same - Death ensues!

CREATE DEFAULT Error again.....

The only difference I can think of is the fact that I have an INSERT Trigger on my main parent table tbl_Job_Raw_XML.

I will re-run the tests on my Parent->Child->Grand Child tables but with a TRIGGER on tbl_Temp_Parent to see if that makes any difference.

Sorry for blatting this all down, just thought I would show that I am trying!

I just hope it is the TRIGGER!

Kind Regards........

Simon.


ChrisRickard on Feb 20, 2008 at 10:36:54 AM (# 10)

One thing I suggest is running profiler when this happens. Look for the offending SQL call. It may give you some clues.


swjs on Feb 20, 2008 at 11:25:27 AM (# 11)

Hi Chris,

Peace and harmony has been restored!

The problem was caused by having columns in the table which take their default from a previously defined Default.

If the values for these columns are not supplied in the XML, then somehow SQLXMLBulkLoad throws a wobbly.

If you simply hard-code Default values eg 0 or CURRENT_TIMESTAMP in the Table Designer, and not reference a predefined Default eg :-

create default [dflt_Now] as CURRENT_TIMESTAMP

or

create default [dflt_Zero] as 0

Then the SQLXMLBulkLoad works a treat.

All the Identity keys are correctly propogated.

So the answer was in the error "CREATE DEFAULT"! Which in this case meant, do not use predefined Defaults on a table definition, if you expect Identity Id's to be propogated to child tables. If you are not populating Child tables it all just works!

Yipppppeeee!

Many thanks for your patience and guidance. Much appreciated.

Kind regards............

Simon..................


ChrisRickard on Feb 20, 2008 at 5:07:52 PM (# 12)

I'm glad to know you're all fixed up. While I didn't really do anything for you directly, I guess I helped you help yourself, so you're welcome.


Earlier Replies | Replies 6 to 12 of 12 | Later Replies
Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.