Re: Constraint violated but no exception thrown by davisonm
davisonm
Wed Jan 05 09:25:03 CST 2005
The online doc does say that DBConcurrencyException is thrown whenever the
result is zero rows. My 'real' try-catch block is more like this:
Try
Dim MyChanges As DataTable = MyDataTable.GetChanges
Dim Count As Integer = MySqlAdapter.Update(MyChanges)
MyDataSet.AcceptChanges()
MyDataSet.Merge(MyChanges, False, MissingSchemaAction.Error)
MyDataSet.AcceptChanges()
Catch dbcx As DBConcurrencyException
Catch ex As System.Data.SqlClient.SqlException
Catch ex As Exception
End Try
My understanding is that 'ex as Exception' will catch everything not
previously caught, but, in fact, none of the catchers catch. Do you see a
problem with those catch statements, or the ordering?
As for ContinueUpdateOnError , I have always left that in the default/false
state, except for flipping it for a test to confirm that it made no
difference, then resetting it.
I do have a OnRowUpdated event to manage the merge of returned PK identity
values. The event code is:
If e.StatementType = StatementType.Insert Then
e.Status = UpdateStatus.SkipCurrentRow
End If
And it fires (I had checked that before), and, whuddayaknow, the error is
visible there (I had not checked that before):
"Violation of UNIQUE KEY constraint 'akChemicalCasNumber'.
So, is this where the exception is getting consumed? As well as the place
where I must handle it? If so, this is manageable, although it's
inconvenient to catch the same exceptions in two places. Everything is so
deeply intertwingled in .NET, sometimes it makes me crazy.
I'd appreciate it if you would confirm your diagnosis, and provide any other
comments you have.
Thanks,
Mark
"Uwe Hafner" wrote:
> Hi,
>
> Haven't looked at this issue for a while now but doesn't the Adapter throw a
> DBConcurrencyException rather than a SqlException in this case?
> Are you sure there is no other exception thrown?
>
> Do you handle OnRowUpdated event? how?
> Do you maybe set ContinueUpdateOnError to true?
>
> hth
> Uwe
>
> "davisonm" <davisonm@discussions.microsoft.com> schrieb im Newsbeitrag
> news:61C08D6E-34EA-4706-B1D8-B8DE9C23ED36@microsoft.com...
> > I have a VB Windows form that calls the DataAdapter.Update method, passing
> a
> > DataTable of one row with RowState = 'Added'. This is the stripped-down
> code:
> >
> > Try
> > Dim Count As Integer = MySqlAdapter.Update(MyDataTable.GetChanges)
> > Catch ex As System.Data.SqlClient.SqlException
> > MessageBox.Show("Update failed: " & ex.Message)
> > End Try
> >
> > The underlying table, in SQL Server 2000, has a unique constraint defined
> on
> > a non-PK data column. When that column has a DataTable value which
> violates
> > the constraint, the DB refuses to add the row, Update returns zero for a
> > rowcount, but there is no exception thrown.
> >
> > Why not?
> >
> > Client: Windows XP SP1, Visual Studio 2003 version 7.1.3088, .NET
> Framework
> > 1.1 version 1.1.4322 SP1, MDAC 2.8 RTM
> > Server: Windows NT 5.0 (Build 2195: Service Pack 2), SQL Server 2000
> version
> > 8.00.760
> >
>
>
>