Hello.
I'm triing to use UpdateGrams to save data:
XML:
<updg:sync>
<updg:before>
</updg:before>
<updg:after>
<Image ProductList="11" ObjectType="3" MimeType="image/png" Content="AAAAAAAAAAQAC" EditDate="08/31/2006 14:27:16" AuthorID="5"></Image>
</updg:after>
</updg:sync>
XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="ImageProduct"
parent="Images"
parent-key="ID"
child="ProductImage"
child-key="ImageID" />
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="Image" sql:relation="Images" sql:key-fields="ID">
<xsd:complexType>
<xsd:attribute name="ID" sql:field="ID" type="xsd:integer" />
<xsd:attribute name="Content" sql:field="ImgData" type="xsd:base64Binary" />
<xsd:attribute name="MimeType" sql:field="ImgType" type="xsd:string" />
<xsd:attribute name="Name" sql:field="Name" type="xsd:string" />
<xsd:attribute name="AuthorID" sql:field="AuthorID" type="xsd:integer" />
<xsd:attribute name="StateID" sql:field="StateID" type="xsd:integer" />
<xsd:attribute name="EditDate" sql:field="EditDate" type="xsd:dateTime" />
<xsd:attribute name="ObjectType" sql:field="TypeID" type="xsd:integer" />
<xsd:attribute name="ProductList" sql:relation="ProductImage"
sql:field="ProductID"
sql:relationship="ImageProduct"
type="xsd:IDREFS" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
Error:
HRESULT="0x80040e14" Description="Cannot insert explicit value for identity column in table 'Images' when IDENTITY_INSERT is set to OFF.
What is the matter? Why does SQL Server try insert ID into Images table?
It tries to insert it because you map it in your annotated schema and provide a value for it. Either avoid mapping it or set IDENTITY_INSERT to ON before you run the updategram.
Best regards
Michael
|||Hello, Michael.
Sorry, but I don't provide value for ID column. There is no ID attribute in the XML I posted above. Actually ID is autoincrementable column.
|||Your mapping schema includes a mapping of the ID field...
<xsd:attribute name="ID" sql:field="ID" type="xsd:integer" />
Thus if you have no value it will try to explictly insert a NULL value and it will fail. Try it without mapping the attribute.
Best regards
Michael
No comments:
Post a Comment