I’ve created an office add-in that allows a user to automatically create a new workorder from a selected object. I’ve managed to successfully create the workorder in the Ayanova database (using the api), but my program continues to throw this error during the workorder.save():
“A first chance exception of type ‘System.Reflection.TargetInvocationException’ occurred in CSLA.Server.DataPortal.DLL”
The .isSaveAllowed and .isSavable properties are true, andthe save seems to be successful, but I’m having trouble figuring out how to prevent this error.
rhafer (2/5/2010)I’ve created an office add-in that allows a user to automatically create a new workorder from a selected object. I’ve managed to successfully create the workorder in the Ayanova database (using the api), but my program continues to throw this error during the workorder.save():
“A first chance exception of type ‘System.Reflection.TargetInvocationException’ occurred in CSLA.Server.DataPortal.DLL”
The .isSaveAllowed and .isSavable properties are true, andthe save seems to be successful, but I’m having trouble figuring out how to prevent this error.
Your recommendations are appreciated. Thank you.
Hi Rhafer, as is mentioned in the comments for the sample projects in the api examples download, but probably not enough everywhere else:
You need to “crack” exceptions coming from the AyaNova business object level because everything goes through a dataportal which enables the ability to work with remoting if configured that way.
This means that ever exception that comes back is coming from a chain that ends up going through the dataportal lastly which wraps the original exception inside the TargetInvocationException so if you get an exception while using the biz object library it will almost always be a target invocation exception, however, if you check inner exception property of the exception it will contain the actual error from the business object.
So what you would typically do is in your exception handler you’d have (pseudo c# typed off the top of my head guranteed not to compile) code like this:
try{
SomeThingInvolvingAyaNovaBusinessObjects();
}
catch(exception e)
{
while(e.InnerException!=null)
e=e.InnerException;
//Now e contains the actual exception from the business object level
}
Just guessing off the top of my head but it might be a rights issue or something, the inner exception should reveal the case.
P.S. don’t forget if you intend to keep using that Workorder object after you save it to cast the return from the save operation to a Workorder and use that instead as outlined in the api docs.
Before I get too confident, here is my exception message. Can you see what i’m missing from this?
—> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column ‘ASAVEDMESSAGE’, table ‘AyaNova_Dev.dbo.ANOTIFYEVENT’; column does not allow nulls. INSERT fails.
I am using SQL 2008, and testing on a copy of our database, not the live one. I have been running my 6.1 Ayanova software on this database without any problems.
Hi there, sorry for the delay but I’ve been researching this problem.
It appears that the asavedmessage column in the table anotifyevent is set to not allow nulls.
That was a bug that should have only existed in firebird db’s as the mssql ones were correctly defined in the original schema update that added that column.
What I’m speculating happened in your case is your db was created from a firebird db from release 6.0 using the ToMSSQL utility we provide which would have copied that bad column null definition over.
I’ve made a case to put the same fix in we did for firebird in the 6.1 release for mssql in our upcoming 6.2 release.
In the mean time if you run the following sql against your sql db it will do the same fix:
alter table anotifyevent alter column asavedmessage nvarchar(1024) NULL
Or use sql server management studio to set ASAVEDMESSAGE to allow nulls, either way, same effect.
I’d like to know if this fixes the problem for you, it should and it would then confirm the problem. Also I’d like to know if my theory that it’s a Firebird db converted to MSSQL at version 6.0 (at the time) is correct.
Cheers!
P.S. What I don’t understand is why you don’t get that error while running AyaNova and creating a workorder, you really should, it’s the same code that you would be using through the API. Perhaps it’s related to the client having notification turned on or the user account being used which is different but if you recreate the same thing you’re doing in code in AyaNova it should give the same error.