BusinessLayerException error message


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi All,

I am testing on a simple form with a one field and when trying to save I got the error below:

BusinessLayerException
  An error occurred while saving an the data to the server.
DataLayerSavingException
  The INSERT statement conflicted with the FOREIGN KEY constraint "Relation_203". The conflict occurred in database "ATR", table "dbo.Buildings", column 'PK_Buildings'.
The statement has been terminated.
SqlException
  The INSERT statement conflicted with the FOREIGN KEY constraint "Relation_203". The conflict occurred in database "ATR", table "dbo.Buildings", column 'PK_Buildings'.
The statement has been terminated.

Source     : MicroFour StrataFrame Business

The table ServiceCalls is related to the table Buildings, but in the form only a ServiceCallsBO is in place.

I will appreciate if anybody could help me figure out what may be wrong in this case.  I am new to SF, VB.NET & MS-SQL Express 2005.  My background is with Visual FoxPro.

Thanks

Edhy Rijo

Replies
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
If the ServiceCall is the child, but it does not necessarily have a building as it's parent, then yes, you changed the correct property.  Your only other option would be to enforce the relationship, but create a "dummy" building record that is the "catch-all" for the service calls that don't have a building.  That way, you end up with a "<No Building Assigned>" building record and all of the service calls are still attached to a building, but might be attached to that one.

It all makes sense on the way you want to query the records.  If you want to join the ServiceCalls to the Buildings table, you will have to to an OUTER JOIN to get the ServiceCalls that don't have an assigned building.  Where as, if you create the dummy record, both an INNER JOIN and an OUTER JOIN will retrieve the records.  It's all up to you.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ben Chase (09/19/2007)
Your only other option would be to enforce the relationship, but create a "dummy" building record that is the "catch-all" for the service calls that don't have a building.  That way, you end up with a "<No Building Assigned>" building record and all of the service calls are still attached to a building, but might be attached to that one.

Hi Ben,

Thanks for the confirmation and your new idea above, I do like it and I am considering implementing the dummy  building record.  If it is not too much to ask, could you elaborate a bit on this idea on how to accomplish this with SF?  So far I know I can create the record manually with specific PK or add another field to flag this record as a dummy one, but then how to tell the ServiceCalls form to use that record for non assigned building?  Is the answer by knowing ahead of time the PK or the flag field of the dummy record and setting it as default for the combobox lookup field of the ServiceCallsBO?

Also another question, does SF has anything to do with handling the enforcement of referential integrity or it is the sole responsibility of the database to handle that?

Edhy Rijo

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
We help along the referential integrity by setting foreign key values when you specify a relationship within the business objects, but we don't enforce referential integrity; that's the sole responsibility of the database.

As for using a dummy record, there are a couple of ways you could go about doing this.  You could know the PK ahead of time, either because you manually assigned it (IDENTITY INSERT ON) and always use the same PK, or because you put a flag on the record and retrieve it when you start up the application.  Either way you would have the PK in a shared variable or a constant somewhere that would allow you to assign the value within the SetDefaultValues() of a business object.  So, records would start out bound to that dummy record unless the user chooses to assign them to a different building.

Like I said, though, you certainly don't have to use a dummy record, and if keeping track of the dummy record is a pain, then using 0 (which you would always know) would certainly work, too, but you would have to turn off the enforcing of your PK (cascading deletes/updates would still work, though because you have the relationship defined, turning off the enforcement only prevents the DB from throwing an exception when the relationship isn't followed).

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ben,

Once again, thanks for your input.  Now I know how to get there in either case.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Edhy Rijo - 18 Years Ago
Trent L. Taylor - 18 Years Ago
Edhy Rijo - 18 Years Ago
Trent L. Taylor - 18 Years Ago
Edhy Rijo - 18 Years Ago
                         If the ServiceCall is the child, but it does not necessarily have a...
StrataFrame Team - 18 Years Ago
                             [quote][b]Ben Chase (09/19/2007)[/b][hr]Your only other option would...
Edhy Rijo - 18 Years Ago
                                 We help along the referential integrity by setting foreign key values...
StrataFrame Team - 18 Years Ago
                                     Hi Ben, Once again, thanks for your input. Now I know how to get...
Edhy Rijo - 18 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search