Click here to Skip to main content
15,886,422 members
Home / Discussions / Database
   

Database

 
JokeRe: Stored Procedure Pin
Daniel Santillanes8-Dec-05 13:56
professionalDaniel Santillanes8-Dec-05 13:56 
Questionado.net odbc insert problem Pin
pgfrancis17-Dec-05 16:24
pgfrancis17-Dec-05 16:24 
AnswerRe: ado.net odbc insert problem Pin
Colin Angus Mackay8-Dec-05 0:04
Colin Angus Mackay8-Dec-05 0:04 
GeneralRe: ado.net odbc insert problem Pin
pgfrancis18-Dec-05 9:11
pgfrancis18-Dec-05 9:11 
QuestionHow to audit user activities in ms access Pin
Mekong River7-Dec-05 15:40
Mekong River7-Dec-05 15:40 
AnswerRe: How to audit user activities in ms access Pin
S Douglas8-Dec-05 0:47
professionalS Douglas8-Dec-05 0:47 
GeneralRe: How to audit user activities in ms access Pin
Mekong River8-Dec-05 4:28
Mekong River8-Dec-05 4:28 
QuestionUsing SQLXML, Bulk Insert XML with IDENTITY Column ... Pin
cmacgowan7-Dec-05 8:53
cmacgowan7-Dec-05 8:53 
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


///////////////////////////////////////////////////
// The code
char progID[] = "SQLXMLBulkLoad.SQLXMLBulkload.3.0";
CLSID clsid;
wchar_t wide[80];
mbstowcs(wide, progID, 80);
CLSIDFromProgID(wide, &clsid);
ISQLXMLBulkLoad* pISQLXMLBulkLoad = NULL;
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ISQLXMLBulkLoad, (void**)&pISQLXMLBulkLoad)))
{
hResult = pISQLXMLBulkLoad->put_ConnectionString(bstrConnect);
hResult = pISQLXMLBulkLoad->put_ErrorLogFile(bstrXmlErrorLogFile);
hResult = pISQLXMLBulkLoad->put_KeepIdentity((bool)TRUE);
hResult = pISQLXMLBulkLoad->Execute(bstrXmlSchemaFile, vXmlDataFile);
}


///////////////////////////////////////////////////
// xml data (successful) RecordId is included
<ROOT>
<Customers>
<RecordId>1</RecordId>
<CustomerID>1111</CustomerID>
<CompanyName>Sean Chai</CompanyName>
<City>NY</City>
</Customers>
<Customers>
<RecordId>2</RecordId>
<CustomerID>1112</CustomerID>
<CompanyName>Tom Johnston</CompanyName>
<City>LA</City>
</Customers>
<Customers>
<RecordId>3</RecordId>
<CustomerID>1113</CustomerID>
<CompanyName>Institute of Art</CompanyName>
</Customers>
</ROOT>

///////////////////////////////////////////////////
// xsd schema file (successful) RecordId is included
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">

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

///////////////////////////////////////////////////
// xml data (fails) attempting to use identity column
<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>

///////////////////////////////////////////////////
// xsd schema file (fails) attempting to use identity column
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">

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


///////////////////////////////////////////////////
// table
CREATE TABLE [MacgowanTestCust] (
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,
[CustomerID] [int] NOT NULL ,
[DataSourceId] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_MacgowanTestCust_DataSourceId] DEFAULT ('OH'),
[CompanyName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[City] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PRIMARY KEY CLUSTERED
(
[RecordId]
) ON [PRIMARY]
) ON [PRIMARY]
GO


///////////////////////////////////////////////////
// error message
<?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>






Questiontrace the computer name Pin
Goodway7-Dec-05 4:14
Goodway7-Dec-05 4:14 
AnswerRe: trace the computer name Pin
miah alom7-Dec-05 6:53
miah alom7-Dec-05 6:53 
GeneralRe: trace the computer name Pin
Goodway9-Dec-05 5:39
Goodway9-Dec-05 5:39 
GeneralRe: trace the computer name Pin
miah alom9-Dec-05 5:55
miah alom9-Dec-05 5:55 
Questiondataset getchanges() question Pin
NikoTanghe7-Dec-05 0:58
NikoTanghe7-Dec-05 0:58 
AnswerRe: dataset getchanges() question Pin
jonathan157-Dec-05 3:55
jonathan157-Dec-05 3:55 
GeneralRe: dataset getchanges() question Pin
miah alom7-Dec-05 4:54
miah alom7-Dec-05 4:54 
Questionms sql server biggest data type Pin
kasko_6-Dec-05 15:05
kasko_6-Dec-05 15:05 
AnswerRe: ms sql server biggest data type Pin
toxcct6-Dec-05 22:43
toxcct6-Dec-05 22:43 
AnswerRe: ms sql server biggest data type Pin
Daniel Santillanes7-Dec-05 13:39
professionalDaniel Santillanes7-Dec-05 13:39 
QuestionHow to create a code parser? Pin
Lord Kixdemp6-Dec-05 12:35
Lord Kixdemp6-Dec-05 12:35 
AnswerRe: How to create a code parser? Pin
toxcct6-Dec-05 22:31
toxcct6-Dec-05 22:31 
GeneralRe: How to create a code parser? Pin
Lord Kixdemp10-Dec-05 9:25
Lord Kixdemp10-Dec-05 9:25 
QuestionExport public keys from certificate Pin
Russell Jones6-Dec-05 4:13
Russell Jones6-Dec-05 4:13 
QuestionToWords() Method within crystal Report Pin
achrafus6-Dec-05 2:07
achrafus6-Dec-05 2:07 
AnswerRe: ToWords() Method within crystal Report Pin
Russell Jones6-Dec-05 4:25
Russell Jones6-Dec-05 4:25 
AnswerRe: ToWords() Method within crystal Report Pin
Russell Jones6-Dec-05 5:23
Russell Jones6-Dec-05 5:23 

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.