Need the name of a DB Exception

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A simple question.

Could somebody give me the exception name for a duplicate index, primary key or relationship. It'd be something like DBConcurrencyException. It'd be DB?Exception. Please help.

polynomial5d
 
Hi,

It depends on the database.
For example: there is SqlException (when you deal with sqlclient) which has
Errors collection that returns all database errors.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

A simple question.

Could somebody give me the exception name for a duplicate index, primary
key or relationship. It'd be something like DBConcurrencyException. It'd be
DB?Exception. Please help.
 
I'm using an access database with oledb, naturally. I can't find anything like oledbException or any collection. Can you help me please

polynomial5

----- Miha Markic [MVP C#] wrote: ----

Hi

It depends on the database
For example: there is SqlException (when you deal with sqlclient) which ha
Errors collection that returns all database errors

--
Miha Markic [MVP C#] - RightHand .NET consulting & developmen
miha at rthand co
www.rthand.co

A simple question
key or relationship. It'd be something like DBConcurrencyException. It'd b
DB?Exception. Please help
 
Hi,

There is System.Data.OleDb.OleDbException class which holds Errors
collection.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

polynomial5d said:
I'm using an access database with oledb, naturally. I can't find anything
like oledbException or any collection. Can you help me please?
polynomial5d

----- Miha Markic [MVP C#] wrote: -----

Hi,

It depends on the database.
For example: there is SqlException (when you deal with sqlclient) which has
Errors collection that returns all database errors.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

message news:D[email protected]...
A simple question.
primary
key or relationship. It'd be something like DBConcurrencyException. It'd be
DB?Exception. Please help.
 
OK, I opened the debug menu and clicked on exceptions. There were a number of system.data.exceptions listed, but none seemed to have anything to do with duplicate indices or primary keys.

There was one that said DuplicateNames. I looked into that but it referred to duplicate table or relationship names

However, I still get a message that tells me the update failed because I have duplicate primary keys, etc. Where is this message coming from? It seems to me there has to be a particular exception that refers to that message? Yet none apply

I even put in a messagebox MsgBox(ex.GetType.ToString

It returned system.data.oledb.oledbexception. That's nebulous indeed

Any ideas? I really need to isolate an exception caused by duplicate primary keys

polynomial5d
 
dear cor and miha. Thank you muchly. I've already looked at this exceptions class. It still didn't list the exceptions available. However, I'll try the Hresult and the errors collection and see what happens. It'll take some time and in any case a friend's daughter is getting married in a few hours. I'll answer tomorrow. I've really got to solve this

polynomial5d
 
Hi,


polynomial5d said:
OK, I opened the debug menu and clicked on exceptions. There were a
number of system.data.exceptions listed, but none seemed to have anything to
do with duplicate indices or primary keys.
There was one that said DuplicateNames. I looked into that but it
referred to duplicate table or relationship names.
However, I still get a message that tells me the update failed because I
have duplicate primary keys, etc. Where is this message coming from? It
seems to me there has to be a particular exception that refers to that
message? Yet none apply.
I even put in a messagebox MsgBox(ex.GetType.ToString)

It returned system.data.oledb.oledbexception. That's nebulous indeed.

You should cast ex to oledbexception (since it is a OleDbException) or even
better do a
catch oledbex as OleDbException
Dim oledex as oledbexception = CType(ex, oledbexception )
and then access its Errors collection.
 
Miha, I tried the errors collection but I couldn't make it work. The sqlIndex for the error I wanted is 3022

If 3022(which I verified in several ways) I wanted only a the message describing the error, and then refill the dataset, because the dataset doesn't automatically throw away the duplicate entry

If another error, I wanted a full description with the message that the form will be closed. I tried this in several ways as well

None of them had any effect at all. Then I tried just before the end of the sub to call the form load event. All this is at the bottom of the code snippet. The form load event call rejects the byval declaration, saying 'expression needed'. Do you have any ideas how to do this? It must be something .net programmers do every day, but I'm not experienced

thank you

polynomial5

Private Sub btnSubmitChanges_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmitChanges.Clic
Dim Check As Integer =
If DsDT1.HasChanges The
DTypeOpened = Fals
Tr
Dim intModified As Intege
intModified = daDT.Update(DsDT1.DateType
Dim strOutput As Strin
strOutput = "Modified " & intModified & " item(s)
MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information
DTypeOpened = Tru
Dim s = ControlChars.CrL
Catch ex As OleDbExceptio
If ex.Errors(0).SQLState = 3022 The
MsgBox(ex.Errors(0).Message & s & "Please try again"
Check =
Exit Tr
End I
Dim errorMessages As Strin
Dim i As Intege
For i = 0 To ex.Errors.Count -
errorMessages += "Index #" & i.ToString() & ControlChars.CrLf
& "Message: " & ex.Errors(i).Message & ControlChars.CrLf
& "NativeError: " & ex.Errors(i).NativeError & ControlChars.CrLf
& "Source: " & ex.Errors(i).Source & ControlChars.CrLf
& "SQLState: " & ex.Errors(i).SQLState & ControlChars.CrLf
& "The form will be closed
Check =
Next
MsgBox(errorMessages
Catch ex As Exceptio
MsgBox(ex.GetType.ToString
MsgBox(ex.Message & s & ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s & ex.TargetSite
Check =
'MessageBox.Show(ex.Message + s + ex.HelpLink + s + ex.InnerException + s + ex.Source + s + ex.TargetSite, "Update failed!", MessageBoxButtons.OK, MessageBoxIcon.Error
End Tr
Els
MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information
End I
'If Check = 1 Then daDT.Fill(DsDT1, "DateType"
'If Check = 2 Then Me.Close(
'frmDateType_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
End Su

Just read your latest reply. I'll try that too, but I don't see how will solve the above problem

polynomial5d
 
Back
Top