Hey there, vb6 automatically open a message box when executing a Store Procedure (recordset.open etc..) but how i catch that error and create a custom one because i cant catch the error with the err.number(-2147217873).
I'm currently using this method to catch unique Key constraint
Code:
set rsC = rs.clone
rsC.Requery
rsC.Filter = "CDMId =" & cboCDMID & " And " & "InsId =" & cboInsID
If rsC.RecordCount > 0 Then
Msg "CDMID '" & cboCDMID & "', InsID '" & cboInsID & "' is already registered", ""
cboCDMID.SetFocus
Exit Sub
Else
rsN.Open nSelect, CnString, adOpenDynamic, adLockOptimistic
FColorW
cboCDMID.SetFocus
End If
The problem is that the requery is slow with large data.
How to catch in VB6 an create a custom/friendly Msbox error from a SqlServer/Store Procedure? Thanks
I think you need to try and catch it in the stored procedure not VB. Take a look at this link. About three pages down it's catching a constraint error.
Does "i cant catch the error" mean that an error handler doesn't help, or that you don't know how to make one?
If you don't know how, see the article about it in the "Dealing with Errors" section of our Classic VB FAQs(in the FAQ forum, which is shown near the top of our home page)
I think you need to try and catch it in the stored procedure not VB. Take a look at this link. About three pages down it's catching a constraint error.
That's just luck I'm afraid - you aren't checking the error code at all (what you are accidentally doing there is actually a Bit manipulation and conversion to boolean, which will always be true).
It should be like this:
Code:
If Err.Number = adRecIntegrityViolation Or Err.Number = adErrIntegrityViolation Then
Have you considered the business logic? I don't know what your app is doing but it seems you should be able to handle not allowing duplicates. Why would someone be picking the DB keys?
Have you considered the business logic? I don't know what your app is doing but it seems you should be able to handle not allowing duplicates. Why would someone be picking the DB keys?
how to check for duplicate without picking the db?
That looks like an error within your application, but being handled by a different part of the program, because your current error handler doesn't deal with it (so the error gets raised to the caller).
I should have thought of this before:
Code:
errHandler:
If Err.Number = adRecIntegrityViolation Or Err.Number = adErrIntegrityViolation Then
Msg "Ya existe un record similar", ""
Else
Msg "Error " & Err.Number & ": " & Err.Description
End If
Once you know the actual error number, you can use that in the If statement.