Im stuck....

Im stuck....

Old forum URL: forums.lhotka.net/forums/t/7518.aspx


gbk posted on Thursday, August 27, 2009

Hey there

CSLA is very new to me, and im only starting to use it recently. So the problem that i have might be a piece of cake for the rest of you.

Im trying to update but cant seem to get it right. Im using connectionManager and stored procs to manipulate data in tables. I got it right to retrieve the data but when i try to update it using the myAcc.Save() method then it gives me an error that says.

DataPortal.Update failed (System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object 'dbo.Accounts' with unique index 'IX_Accounts_AccountNo'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at AccSageProject.Library.Account.DataPortal_Insert() in C:\Users\TEMP\Documents\Celeste\AccSageV1.4.2\WindowsApplication1\Account.vb:line 261
at dm(Object , Object[] )
at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\Visual Studio Projects\CSLA\Source\cslacs\Csla\Reflection\MethodCaller.cs:line 332)

Please HELP... or provide any other way to help me update

Thanks in advance

skagen00 replied on Thursday, August 27, 2009

Is it your intention to have AccountNo be unique? (i.e. may be entirely valid to not be unique if accounts are held within different institutions of course).

If they can overlap, you just need to change your index to not be unique.

Is this insert somehow getting run twice when you're saving? (just throw a breakpoint on it).

Tom_W replied on Friday, August 28, 2009

Hi gbk

Just to state the very obvious, and I'm sure you've realised all of this, but just in case:
The reason for this are likely to be one (or more of) of:

HTH

Copyright (c) Marimer LLC