Click here to Skip to main content
15,899,679 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to resize a dynamic array??? Pin
Ming Luo7-Dec-05 10:52
Ming Luo7-Dec-05 10:52 
AnswerRe: How to resize a dynamic array??? Pin
Jörgen Sigvardsson7-Dec-05 11:56
Jörgen Sigvardsson7-Dec-05 11:56 
GeneralRe: How to resize a dynamic array??? Pin
Matt Godbolt7-Dec-05 12:07
Matt Godbolt7-Dec-05 12:07 
GeneralRe: How to resize a dynamic array??? Pin
Jörgen Sigvardsson8-Dec-05 1:25
Jörgen Sigvardsson8-Dec-05 1:25 
QuestionWindows Start/Boot time Pin
Inocentric7-Dec-05 10:38
Inocentric7-Dec-05 10:38 
QuestionCfileDialog file filtering Pin
Crislen7-Dec-05 9:27
Crislen7-Dec-05 9:27 
AnswerRe: CfileDialog file filtering Pin
David Crow7-Dec-05 9:55
David Crow7-Dec-05 9:55 
QuestionUsing SQLXML, Bulk Insert XML with IDENTITY Column ... Pin
cmacgowan7-Dec-05 8:48
cmacgowan7-Dec-05 8:48 
Using SQLXML, Bulk Insert XML with IDENTITY Column ...

I have a program that will insert xml data into a table using the SQLXML Bulk Load COM Object. The bulk load is successful when I supply the RecordId in the xml. When I add an IDENTITY column to the table then the bulk load fails with the following error:
[Cannot insert the value NULL into column 'RecordId', table 'Alphanumericdata.dbo.MacgowanTestCust'; column does not allow nulls. INSERT fails.]

From the following article, XML Bulk Load ignores elements and attributes that are not mapped (either because they are not described in the schema, or because they are annotated in the XSD schema with sql:mapped="false"). All unmapped data goes into the overflow column, if such a column is specified by using sql:overflow-field.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlxml3/htm/bulkload_9w9w.asp

I have attempted using sql:mapped="false" in the schema file and not using it .. both fail with the “nulls not allowed” error.

I have also set the KeepIdentity(true) to my pISQLXMLBulkLoad object.

Below is the table, xml, xsd and code ...
Any comments or answers are appreciated.

Thanks,
Chris

<br />
///////////////////////////////////////////////////<br />
//  The code<br />
char progID[] = "SQLXMLBulkLoad.SQLXMLBulkload.3.0";<br />
CLSID clsid;<br />
wchar_t wide[80];<br />
mbstowcs(wide, progID, 80);<br />
CLSIDFromProgID(wide, &clsid);<br />
ISQLXMLBulkLoad* pISQLXMLBulkLoad = NULL;<br />
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ISQLXMLBulkLoad, (void**)&pISQLXMLBulkLoad)))<br />
{<br />
    hResult = pISQLXMLBulkLoad->put_ConnectionString(bstrConnect);<br />
    hResult = pISQLXMLBulkLoad->put_ErrorLogFile(bstrXmlErrorLogFile);<br />
    hResult = pISQLXMLBulkLoad->put_KeepIdentity((bool)TRUE);<br />
    hResult = pISQLXMLBulkLoad->Execute(bstrXmlSchemaFile, vXmlDataFile);<br />
}<br />
 <br />
<br />
///////////////////////////////////////////////////<br />
//  xml data (successful) RecordId is included<br />
<ROOT><br />
  <Customers><br />
    <RecordId>1</RecordId><br />
    <CustomerID>1111</CustomerID><br />
    <CompanyName>Sean Chai</CompanyName><br />
    <City>NY</City><br />
  </Customers><br />
  <Customers><br />
    <RecordId>2</RecordId><br />
    <CustomerID>1112</CustomerID><br />
    <CompanyName>Tom Johnston</CompanyName><br />
     <City>LA</City><br />
  </Customers><br />
  <Customers><br />
    <RecordId>3</RecordId><br />
    <CustomerID>1113</CustomerID><br />
    <CompanyName>Institute of Art</CompanyName><br />
  </Customers><br />
</ROOT><br />
 <br />
///////////////////////////////////////////////////<br />
//  xsd schema file (successful) RecordId is included<br />
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br />
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema"><br />
 <br />
  <xsd:element name="Customers" sql:relation="MacgowanTestCust" ><br />
   <xsd:complexType><br />
     <xsd:sequence><br />
       <xsd:element name="RecordId"    type="xsd:integer" sql:field="RecordId" /><br />
       <xsd:element name="CustomerID"  type="xsd:integer" sql:field="CustomerID" /><br />
       <xsd:element name="CompanyName" type="xsd:string"  sql:field="CompanyName" /><br />
       <xsd:element name="City"        type="xsd:string"  sql:field="City" /><br />
     </xsd:sequence><br />
    </xsd:complexType><br />
  </xsd:element><br />
</xsd:schema><br />
 <br />
///////////////////////////////////////////////////<br />
//  xml data (fails) attempting to use identity column<br />
<ROOT><br />
  <Customers><br />
    <CustomerID>1111</CustomerID><br />
    <CompanyName>Sean Chai</CompanyName><br />
    <City>NY</City><br />
  </Customers><br />
  <Customers><br />
    <CustomerID>1112</CustomerID><br />
    <CompanyName>Tom Johnston</CompanyName><br />
     <City>LA</City><br />
  </Customers><br />
  <Customers><br />
    <CustomerID>1113</CustomerID><br />
    <CompanyName>Institute of Art</CompanyName><br />
  </Customers><br />
</ROOT><br />
<br />
///////////////////////////////////////////////////<br />
//  xsd schema file (fails) attempting to use identity column<br />
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br />
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema"><br />
 <br />
  <xsd:element name="Customers" sql:relation="MacgowanTestCust" ><br />
   <xsd:complexType><br />
     <xsd:sequence><br />
       <xsd:element name="CustomerID"  type="xsd:integer" sql:field="CustomerID" /><br />
       <xsd:element name="CompanyName" type="xsd:string" sql:field="CompanyName" /><br />
       <xsd:element name="City"        type="xsd:string" sql:field="City" /><br />
     </xsd:sequence><br />
    </xsd:complexType><br />
  </xsd:element><br />
</xsd:schema><br />
 <br />
 <br />
///////////////////////////////////////////////////<br />
//  table<br />
CREATE TABLE [MacgowanTestCust] (<br />
    [RecordId] [int] IDENTITY (1, 1) NOT NULL ,<br />
    [CustomerID] [int] NOT NULL ,<br />
    [DataSourceId] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_MacgowanTestCust_DataSourceId] DEFAULT ('OH'),<br />
    [CompanyName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<br />
    [City] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<br />
     PRIMARY KEY  CLUSTERED<br />
    (<br />
        [RecordId]<br />
    )  ON [PRIMARY]<br />
) ON [PRIMARY]<br />
GO<br />
 <br />
 <br />
///////////////////////////////////////////////////<br />
//  error message<br />
<?xml version="1.0"?><Error><Record><HResult>0x80004005</HResult><SQLState>01000</SQLState><NativeError></NativeError><ErrorState>1</ErrorState><Severity>0</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[The statement has been terminated.]]></Description></Record><Record><HResult>0x80004005</HResult><SQLState>23000</SQLState><NativeError></NativeError><ErrorState>2</ErrorState><Severity>16</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[Cannot insert the value NULL into column 'RecordId', table 'Alphanumericdata.dbo.MacgowanTestCust'; column does not allow nulls. INSERT fails.]]></Description></Record></Error><br />
 <br />
<br />
 <br />
<br />

AnswerRe: Using SQLXML, Bulk Insert XML with IDENTITY Column ... Pin
cmacgowan7-Dec-05 8:52
cmacgowan7-Dec-05 8:52 
Question[Message Deleted] Pin
NET_GEEK7-Dec-05 8:44
NET_GEEK7-Dec-05 8:44 
AnswerRe: Classic visual C++ and Visual C++.net Pin
Nish Nishant7-Dec-05 8:50
sitebuilderNish Nishant7-Dec-05 8:50 
QuestionMy dialog's close button not working? Pin
G Haranadh7-Dec-05 7:56
G Haranadh7-Dec-05 7:56 
AnswerRe: My dialog's close button not working? Pin
Shay Harel7-Dec-05 8:21
Shay Harel7-Dec-05 8:21 
GeneralRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 8:40
G Haranadh7-Dec-05 8:40 
QuestionRe: My dialog's close button not working? Pin
David Crow7-Dec-05 9:06
David Crow7-Dec-05 9:06 
AnswerRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 18:23
G Haranadh7-Dec-05 18:23 
AnswerRe: My dialog's close button not working? Pin
Nish Nishant7-Dec-05 8:51
sitebuilderNish Nishant7-Dec-05 8:51 
GeneralRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 18:29
G Haranadh7-Dec-05 18:29 
QuestionApplication's Icon Pin
Shay Harel7-Dec-05 7:36
Shay Harel7-Dec-05 7:36 
AnswerRe: Application's Icon Pin
toxcct7-Dec-05 7:42
toxcct7-Dec-05 7:42 
GeneralRe: Application's Icon Pin
Shay Harel7-Dec-05 8:19
Shay Harel7-Dec-05 8:19 
QuestionHow to handle events fired from ActiveX control Pin
Ian Bowler7-Dec-05 7:03
Ian Bowler7-Dec-05 7:03 
AnswerRe: How to handle events fired from ActiveX control Pin
Roger Stoltz7-Dec-05 12:24
Roger Stoltz7-Dec-05 12:24 
GeneralRe: How to handle events fired from ActiveX control Pin
Ian Bowler8-Dec-05 8:53
Ian Bowler8-Dec-05 8:53 
QuestionCreate a Window witch is always on bottom z order Pin
desir7-Dec-05 7:01
desir7-Dec-05 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.