﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » DB2 record add problem</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Thu, 28 May 2026 16:12:05 GMT</lastBuildDate><ttl>20</ttl><item><title>DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12072.aspx</link><description>So..... I got my DB2 project working to display and edit existing records.&lt;br&gt;
&lt;br&gt;
When I try to add a record I always get a conversion error on the primekey field. &lt;br&gt;
&lt;br&gt;
I know DB2 doesn't have auto increment fields (does it?) so I have to manually manage the primekeys but I don't even get a chance. I get this error as soon as I hit the add button, or programmatically call BO.add().&lt;br&gt;
&lt;br&gt;
I have two projects referencing two different libraries/tables with primekeys of different data types exhibiting the same behavior.&lt;br&gt;
&lt;br&gt;
Any ideas? Please see the attached error image, I cant seem to add images to posts anymore.</description><pubDate>Thu, 01 Nov 2007 12:00:08 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12352.aspx</link><description>[quote][b]Keith Chisarik (10/23/2007)[/b][hr]Just for anyone that might read this later, DB2 does fully support auto-increment fields, our RPG programmer just doesn't use them so he didn't know they existed.[/quote]&lt;br&gt;
&lt;br&gt;
Thanks Peter, I had finally discovered that on my own, just took me a while :)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Thu, 01 Nov 2007 12:00:08 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12331.aspx</link><description>[quote][b]Keith Chisarik (10/18/2007)[/b][hr]I know DB2 doesn't have auto increment fields (does it?) so I have to manually manage the primekeys but I don't even get a chance. I get this error as soon as I hit the add button, or programmatically call BO.add().[/quote]&lt;br&gt;
&lt;br&gt;
Yes, DB2 can auto-generate primary keys. Here's a CREATE TABLE statement with an auto-generated key field:&lt;br&gt;
&lt;br&gt;
[quote]CREATE TABLE "SW_TYPES_OWN"  (&lt;br&gt;
                  "ID_OWN_TYP" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (&lt;br&gt;
                    START WITH +1&lt;br&gt;
                    INCREMENT BY +1&lt;br&gt;
                    MINVALUE +1&lt;br&gt;
                    MAXVALUE +2147483647&lt;br&gt;
                    NO CYCLE&lt;br&gt;
                    NO CACHE&lt;br&gt;
                    NO ORDER ) ,&lt;br&gt;
                  "NM_OWN_TYP" VARCHAR(125) NOT NULL );[/quote]&lt;br&gt;
&lt;br&gt;
I think you can reset the starting number with a table alter, but I've not had any requirement to do that yet, so I'm not sure what the SQL is. Here's the DB2 v9 SQL reference, though. It should (hopefully) have the information in there.&lt;br&gt;
&lt;br&gt;
[url=http://publibfp.boulder.ibm.com/epubs/pdf/dsnsqk10.pdf]http://publibfp.boulder.ibm.com/epubs/pdf/dsnsqk10.pdf[/url]&lt;br&gt;
&lt;br&gt;
Peter&lt;br&gt;</description><pubDate>Thu, 01 Nov 2007 08:00:38 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12311.aspx</link><description>Just to close this out, I am up and running on DataDirect's DB2 Provider for ADO.NET with the SF framework,  just the changes Ben mentioned above and a syntax change to the INSERT SQL statement was required.&lt;br&gt;
&lt;br&gt;
Thank you.</description><pubDate>Wed, 31 Oct 2007 12:39:59 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12304.aspx</link><description>Yes, the Db2DataSourceItem can be used with any ADO.NET provider that implements the System.Data.Common classes and provides a DbProviderFactory class.&amp;nbsp; However, when you swap to a new ADO.NET provider, you will need to swap the places where you pass Db2Commands to the FillDataTable() methods of the business object to use the new provider as well.</description><pubDate>Wed, 31 Oct 2007 11:10:47 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12285.aspx</link><description>My client is not happy with the performance of the IBM DB2 Provider for .NET.&lt;br&gt;
&lt;br&gt;
As I understand iy SF DB@ support is designed to work with the IBM Provider IBM.DATA.DB2.dll and wont work with other third party providers, is this correct?&lt;br&gt;
&lt;br&gt;
They want to use this.&lt;br&gt;
&lt;br&gt;
http://www.hitsw.com/products_services/sql400/dlsql400.html&lt;br&gt;
http://www.datadirect.com/products/net/net_for_db2/index.ssp</description><pubDate>Tue, 30 Oct 2007 10:50:46 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12189.aspx</link><description>Can you send me the create script for the table, the .vb file and the .designer.vb file for the business object/table that is causing the problems?&amp;nbsp; Also send me the stack trace for the error that you're receiving after you got everything back to ground-zero.&amp;nbsp; I think I'm going to have to run it on this end to see what it's doing.</description><pubDate>Thu, 25 Oct 2007 10:49:17 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12187.aspx</link><description>[quote][b]Keith Chisarik (10/23/2007)[/b][hr]So.........&lt;br&gt;
&lt;br&gt;
I have my DB2 table set to now use auto incrementing keys of type BIGINT.&lt;br&gt;
&lt;br&gt;
I set the PrimaryKeyIsAutoIncremented property to TRUE on the BO.&lt;br&gt;
&lt;br&gt;
I get the following error now:&lt;br&gt;
[b]ERROR [428C9] [IBM][AS] SQL0798N  A value cannot be specified for column "PURCH_PK" which is defined as GENERATED ALWAYS.  SQLSTATE=428C9[/b]&lt;br&gt;
&lt;br&gt;
The field is defined as:&lt;br&gt;
[b]      PURCH_PK BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1)[/b]&lt;br&gt;
&lt;br&gt;
I tried adding the PURCH_PK field to the FieldsToExcludeFromInsert collection to no avail:&lt;br&gt;
[b]Cannot create INSERT command because the updating DataTable does not contain columns for all PrimaryKeyFields.[/b]&lt;br&gt;
&lt;br&gt;
Any ideas why this isn't working? The primekey field does auto-increment if I add records manually using a query &amp;#119;indow.[/quote]&lt;br&gt;
&lt;br&gt;
Ben, I did set it back to TRUE, I am 100% sure of it as I thought that was the problem from the start once I got my database auto-incrementing and tested it a few times over before posting.&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Thu, 25 Oct 2007 09:31:36 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12184.aspx</link><description>Looks like it's trying to insert a value into the PK field because you might still have the PrimaryKeyIsAutoIncremented = False set.&amp;nbsp; Set it back to its default of True and you should be able to save it fine.&amp;nbsp; The Db2DataSourceItem is designed to work with auto-incremented columns the same way as SQL Server, it just uses a different server function to retrieve the next assigned value (where SQL Server uses SCOPE_IDENTITY()).&amp;nbsp; So, it should be working.&amp;nbsp; Re-set that field back to True to get back to ground-zero for this post, where you got the InvalidCastException and we'll go from there.&amp;nbsp;</description><pubDate>Thu, 25 Oct 2007 09:10:41 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12183.aspx</link><description>No problem, thanks.&lt;br&gt;
&lt;br&gt;
Enjoy poking around with DB2 :)&lt;br&gt;
&lt;br&gt;</description><pubDate>Thu, 25 Oct 2007 08:01:42 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12181.aspx</link><description>DB2 is not something I work in every day so before I can just throw an answer out there like I can for SQL Server or some of the other databases.&amp;nbsp; I will have to get it setup and play with it on my side.&amp;nbsp; :)&amp;nbsp; I have not dug into the DB2 server to play with this...yet.&amp;nbsp; But we will look into it.&amp;nbsp; Sorry for the delay :)</description><pubDate>Thu, 25 Oct 2007 07:58:18 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12180.aspx</link><description>OK I will look into that, any thoughts on my bigger problem, the use of auto-incrementing keys with a DB2 datasource?&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Thu, 25 Oct 2007 07:35:23 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12174.aspx</link><description>[quote]also, why would BO.save commit my inserts/updates to the server, yet return FALSE?[/quote]&lt;/P&gt;&lt;P&gt;You might expand on this one since the Save returns an enum value rather than a boolean (i.e. Successful, Failed, etc.)</description><pubDate>Wed, 24 Oct 2007 21:59:06 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12160.aspx</link><description>I went back to using non-incrementing keys so I could get some stuff done until you tell me what is wrong when using DB2 auto-incrementing keys.&lt;br&gt;
&lt;br&gt;
Everything is working the way I want by manually updating a new primekey value in the SetDefaultValue method but I have some questions. we used to do this all the time in VFP but I don't see how it can work in a disconnected data model? If I am creating 5 records on Client A and 5 records on Client B since the data isn't committed to the server until the call to BO.save(), my primekey assignment will fall down since Client B will get the same "next primekey" value from the server until Client A commits their inserts. Hopefully this is a moot point since I really want to use good old server assigned keys but i thought it a vlaid question to ask.&lt;br&gt;
&lt;br&gt;
Also, why would BO.save commit my inserts/updates to the server, yet return FALSE? That is happening to me now.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 24 Oct 2007 09:30:01 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12156.aspx</link><description>Also, I did remove the code from bo.SetDefaultValues.&lt;br&gt;
&lt;br&gt;
I miss my SQL Server right now.&lt;br&gt;
&lt;br&gt;
Thanks.</description><pubDate>Tue, 23 Oct 2007 17:20:59 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12155.aspx</link><description>So.........&lt;br&gt;
&lt;br&gt;
I have my DB2 table set to now use auto incrementing keys of type BIGINT.&lt;br&gt;
&lt;br&gt;
I set the PrimaryKeyIsAutoIncremented property to TRUE on the BO.&lt;br&gt;
&lt;br&gt;
I get the following error now:&lt;br&gt;
[b]ERROR [428C9] [IBM][AS] SQL0798N  A value cannot be specified for column "PURCH_PK" which is defined as GENERATED ALWAYS.  SQLSTATE=428C9[/b]&lt;br&gt;
&lt;br&gt;
The field is defined as:&lt;br&gt;
[b]      PURCH_PK BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1)[/b]&lt;br&gt;
&lt;br&gt;
I tried adding the PURCH_PK field to the FieldsToExcludeFromInsert collection to no avail:&lt;br&gt;
[b]Cannot create INSERT command because the updating DataTable does not contain columns for all PrimaryKeyFields.[/b]&lt;br&gt;
&lt;br&gt;
Any ideas why this isn't working? The primekey field does auto-increment if I add records manually using a query &amp;#119;indow.</description><pubDate>Tue, 23 Oct 2007 17:15:26 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12149.aspx</link><description>Just for anyone that might read this later, DB2 does fully support auto-increment fields, our RPG programmer just doesn't use them so he didn't know they existed.</description><pubDate>Tue, 23 Oct 2007 12:48:29 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12137.aspx</link><description>gotcha</description><pubDate>Mon, 22 Oct 2007 09:20:25 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12135.aspx</link><description>[quote]So then would the process be to always set the primekey field to a default, and then make sure to update it with the "real" primekey before calling save?&lt;BR&gt;[/quote]&lt;/P&gt;&lt;P&gt;Well, this is kindof a trick question.&amp;nbsp; You must have the initialization of the properties turned off for the BO, otherwise this would have at least had a "0" in it when created.&amp;nbsp; So in this case, you will have to assign a value or manage the NULL value.&amp;nbsp; In this particular case, I think that I would go ahead and use a NextID table, like you did in VFP, and assign the "real" PK value in the SetDefaultValues of the BO.</description><pubDate>Mon, 22 Oct 2007 09:17:33 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12106.aspx</link><description>That was it, I didn't set the default value for the primekey field. Your the man.&lt;br&gt;
&lt;br&gt;
So then would the process be to always set the primekey field to a default, and then make sure to update it with the "real" primekey before calling save?&lt;br&gt;
&lt;br&gt;
I was going to use my old VFP way of tracking primekeys that we used before VFP supported auto increment fields, have a table that has a record for each table in the database that contains a field for the next valid primekey.&lt;br&gt;
&lt;br&gt;
I cant believe DB2 doesn't have auto increment fields in 2007.....&lt;br&gt;
&lt;br&gt;
Thanks again for your help. So simple once you know......&lt;br&gt;
&lt;br&gt;</description><pubDate>Fri, 19 Oct 2007 10:26:12 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12099.aspx</link><description>Well, this is happening in the Get of the property so this indicates that something is trying to pull a value.&amp;nbsp; So two things, look at and/or post the call stack so that we can see where it is coming from.&amp;nbsp; Also, have you initialized the field in the SetDefaultValues event?&amp;nbsp; You mentioned that this is happening when you call the Add(), so at this point, the server has never been queried.&amp;nbsp; So more than likely you are not allowing the fields to be initialized and have not set a value in the SetDefaultValues before something is trying to query the property.</description><pubDate>Fri, 19 Oct 2007 09:34:37 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12096.aspx</link><description>Yes changing that property to false is what got me past my problem updating existing records, which I can do fine. I just cant add records.</description><pubDate>Fri, 19 Oct 2007 09:26:11 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12083.aspx</link><description>Keith,&lt;/P&gt;&lt;P&gt;Did you set the PrimaryKeyIsAutoIncrementing to False on the BO?&amp;nbsp; This is probably what is causing your problem.</description><pubDate>Fri, 19 Oct 2007 08:28:42 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: DB2 record add problem</title><link>http://forum.strataframe.net/FindPost12080.aspx</link><description>shameless post bump, I'm stuck at this point</description><pubDate>Fri, 19 Oct 2007 08:18:01 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item></channel></rss>