Dear Axel,
in Italy we say "better late than nothing". Hope this is the case in this situation
Find here attached thinBasic_ADODB.dll in which I have developed a sord of wrapper of internal ADODB errors.
Please unzip in \thinbasic\Lib\ replacing your current one
Developed function are here summarized:
'---To check if there is ana arror, always use connection and Errors.Count method
if pConn.Errors.Count then
'---Print info of at least first error. there can be more than one
printl "Error number..:", pConn.Errors(1).number
printl "Description...:", pConn.Errors(1).Description
printl "Source........:", pConn.Errors(1).Source
printl "SQLState......:", pConn.Errors(1).SQLState
printl "NativeError...:", pConn.Errors(1).NativeError
'---Clear internal errors collection. Otherwise errors collection will accumulate errors in case execution could continue
pConn.Errors.Clear
end if
...
'---To check if there is ana arror, always use connection and Errors.Count method
if pConnection.Errors.Count then
'---Show all errors in one go.
'---This function also clear internal errors collection
printl pConnection.Errors.Msg
end if
Here below an example on how to use new error functions. Example simulate adding a new record that violate table primary key duplication.
Uses "Console"
Uses "ADODB"
Dim pConnection As New ADODB_CONNECTION
Dim sConn As String
'----------------------------------
Function Add_New_Record(byval pConn as adodb_connection, byval sISBN as string, byval lYear as long, byval sTitle as string)
'----------------------------------
Dim pRS As New ADODB_RECORDSET
pRS.Open "Titles", pConn, %ADOPENKEYSET, %ADLOCKOPTIMISTIC, %ADCMDTABLE
if pRS.STATE = %ADSTATEOPEN Then
pRs.UpdateS("ISBN") = sISBN '& " " & Timer'"ich 4711"
pRs.UpdateN("Year Published") = lYear'2016
pRs.UpdateS("Title") = sTitle'"Mein erster satz"
pRs.addnew
'pRs.update
'printl AdoDb_GetErrorInfo(pConn)
PrintL "Add new" In %CCOLOR_FLIGHTRED
'---To check if there is ana arror, always use connection and ErrorsCount method
if pConn.Errors.Count then
'---Print info of at least first error. there can be more than one
printl "Error number..:", pConn.Errors(1).number
printl "Description...:", pConn.Errors(1).Description
printl "Source........:", pConn.Errors(1).Source
printl "SQLState......:", pConn.Errors(1).SQLState
printl "NativeError...:", pConn.Errors(1).NativeError
'---Clear internal errors collection. Otherwise errors collection will cumulate errors in case execution could continue
pConn.Errors.Clear
end if
printL " pRecordSet.Close :", pRS.CLOSE
end if
End Function
'---------------------------------------------------------------
' Connection
'---------------------------------------------------------------
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & APP_SourcePath & "biblio.mdb"
'---Set connection string
pConnection.ConnectionString = sConn
PrintL "-Connection------------------------------------------"
PrintL " Opening ..." , pConnection.OPEN'(sConn)
PrintL " pConnection.Connectionstring:" , pConnection.Connectionstring
PrintL " pConnection.State :" , pConnection.State
PrintL " pConnection.Version :" , pConnection.Version
PrintL "-Press a key to continue------------------------------" In %CCOLOR_FYELLOW
'---To check if there is ana arror, always use connection and ErrorsCount method
if pConnection.Errors.Count then
'---Show all errors in one go.
'---This function also clear internal errors collection
printl pConnection.Errors.Msg
end if
If pConnection.STATE = %ADSTATEOPEN Then
Add_New_Record(pConnection, "999999999", 9999, "Eros Test " & date$(2) & " " & time$(0))
PrintL "-Closing press a key-------------------------------------------" In %CCOLOR_FYELLOW
'WaitKey
PrintL " pConnection.Close :", pConnection.CLOSE
Else
PrintL "-It was not possible to open a connection-" In %CCOLOR_FLIGHTRED
End If
PrintL
PrintL "-Press a key to finish-------------------------------"
WaitKey
Bookmarks