Updating BO causes Business layer exception


Author
Message
Doug Birtell
Doug Birtell
StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)
Group: Forum Members
Posts: 33, Visits: 64
I have created a windows form that maintains a simple table in a SQL Server database.  The first column of this table is also the primary key.

I can add new records to the business object (and underlying table) but when I try to update one of the existing records I get the following error.  The problem table only was one column as the primary key and it is not an identity column (auto generated).  Looking at the partial BO class, it appears that the correct column is being used as the primary key.

BusinessLayerException

  An error occurred while saving an the data to the server.

DataLayerSavingException

  Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.

DataLayerException

  Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.

 

Source     : MicroFour StrataFrame Business

 

Stack Trace:

   at MicroFour.StrataFrame.Data.DataLayer.BuildUpdateInfo(DataTable UpdatingTable, Boolean Transactional, String TransactionKey)

   at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)

   at MicroFour.StrataFrame.Data.DataLayer.SaveByForm(DataTable TableToSave, Boolean Transactional, String TransactionKey)

   at MicroFour.StrataFrame.Business.BusinessLayer.SaveByForm(Boolean Transactional, String TransactionKey)

   at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save(Boolean Transactional, String TransactionKey)

   at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save()

   at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdSave_Click(Object sender, EventArgs e)

   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)

   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)

   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)

   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)

   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)

   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)

   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)

   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

   at System.Windows.Forms.ToolStrip.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)

   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
If the PrimaryKeyField is not auto-incrementing, then set the PrimaryKeyIsAutoIncrementing property on the BO to False and your error should go away. Smile
Doug Birtell
Doug Birtell
StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)
Group: Forum Members
Posts: 33, Visits: 64
Trent,

The property you mention is already set to false.  The strange thing is that I have a similar windows form that does essentially the same thiing and it works fine.  I've compared the two forms, BO's, etc and can not see any difference that would cause this error. 

Thanks!

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Turn on debugging and see what is causing the problem in your statement.  In the AppMain.vb or program.cs file, after the data source connections have been established, turn on the debug.

MicroFour.StrataFrame.Data.Databasics.DataSources("").SetDebugOn("c:\MyDebug.html",True)

Doug Birtell
Doug Birtell
StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)
Group: Forum Members
Posts: 33, Visits: 64
Ok, (an old Java programmer) being new to strataframe (using C#), I'm not sure how to get the debugger turned on via code.  I am unable to find any method in any MicroFour tablespaces that resembles SetDebugOn(...

i.e. there is no method such as SetDebugOn within the DataSources class, or any other class that I can find.  I'm sure it's somewhere, but I can't find it.  ???

I can set breakpoints in the code, but am unable to step into the spot that causes the problem.

MicroFour.StrataFrame.Data.Databasics.DataSources("").SetDebugOn("c:\MyDebug.html",True)

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Doug,



This statement simply exports all the sql that is generated by the indicated datasource to the indicated file, in html format. I.e.



MicroFour.StrataFrame.Data.Databasics.DataSources("").SetDebugOn("c:\MyDebug.html",True)




will write all the sql statements generated by the default data source, with the key of an empty string (DataSources("")) to the "c:\MyDebug.html" file. Typically you set this in the SetDataSources (pretty sure that is its name) method in AppMain. However, you can actually put it anywhere in code after the datasources are set.



When you open this file, you'll see every sql command sent (after debugging has been turned on). This way you can see if the commands being sent to the database are OK. It can really narrow down were to start looking for the problem.



Hope this helps!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Oh, and as to your confusion about SetDebugOn, this is a method of a DataSource, not the DataSources collection. The code is DataSources(""), which is using the default property of the DataSources class (the indexer in C#), which is referencing one of the DataSource items in the collection by it's key (in this case an empty string).
Doug Birtell
Doug Birtell
StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)
Group: Forum Members
Posts: 33, Visits: 64
Greg,

Thanks for the explaination.  I modified the code to log the sql commands as follows

MicroFour.StrataFrame.Data.DataBasics.DataSources[""].SetDebugOn("c:\\MyDebug.html", true);

And here is what the MyDebug.html file contains after getting the exception - BusinessLayerException
  An error occurred while saving an the data to the server.
DataLayerSavingException
  Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.

Command #: 1
Timestamp: 2007-08-22 11:45:03.641
General Command Settings
Command Type: Text
Object Type: System.Data.SqlClient.SqlCommand
Connection String: Data Source=IST022246\SQLEXPRESS;Initial Catalog=FitWearDatabase;Integrated Security=True;Persist Security Info=False;Asynchronous Processing=True
Transaction: False
Command Settings
CommandText: Select * from SampleMaster
Command Parameters
N/A No parameters are defined
Command #: 2
Timestamp: 2007-08-22 11:45:03.922
General Command Settings
Command Type: Text
Object Type: System.Data.SqlClient.SqlCommand
Connection String: Data Source=IST022246\SQLEXPRESS;Initial Catalog=FitWearDatabase;Integrated Security=True;Persist Security Info=False;Asynchronous Processing=True
Transaction: False
Command Settings
CommandText: select * from SampleMaster
Command Parameters
N/A No parameters are defined

The table in question has only the first column defined as the primary key, and the Business Object partial code has the correct column as the primary key.  (non auto-incremeting, and defined as such in the BO) I can add new records but when I try to edit/save a record (via a strataframe maintenance form) I get the above expection.

Thanks for the help!

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, I think Ben will likely have to help you. It doesn't appear to be a SQL problem. I'm guessing the exception occurs when the data source item is attempting to create the SQL for the update, but I don't know enough about the internals to have any idea why it would fail (especially since it works when you add new fields).
Doug Birtell
Doug Birtell
StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)StrataFrame Beginner (33 reputation)
Group: Forum Members
Posts: 33, Visits: 64
Thanks Greg.  It makes sense that it's some generated code someplace that is somehow confused about the primary key attributes of the table.  I'm sure it's something simple that I've done, but after several days trying to find it, I decided to turn to the experts.  Ben, any help you could provide would be greatly appreciated.

Regards,

Doug

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search