Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error code trapping from VB

0 views
Skip to first unread message

Boistuaud Frederic

unread,
Oct 14, 1996, 3:00:00 AM10/14/96
to

Hi folks,

I'm using SQLSErver6.0 with VB4/16 & ODBC. (DAO level)

Can anyone tell me how to trap the error Number generated by SQLServer
if a call fails (Eg: Attempt to insert null into a column that does not
allow null)
It returns: "ODBC Call failed, Error 3146".
I would like it to return : "Msg 515, Level 16, State 3
Attempt to insert the value NULL into column 'C1', table
'StaffDev.dbo.frdTest'; column does not allow nulls. INSERT fails.
Command has been aborted." or at least just the error & State Number

--
Frédéric.

Karl Costenbader

unread,
Oct 14, 1996, 3:00:00 AM10/14/96
to Boistuaud Frederic

You need to traverse the DBEngine.Errors collection to obtain all of the
errors returned by the ODBC driver. Err.Description just returns the
first error in this collection, which is 3146.

--
Karl Costenbader, President
Competent Consulting
Sacramento, CA
EMail: ka...@competent.com
Home Page: http://www.competent.com

Maruthi Kaza

unread,
Oct 16, 1996, 3:00:00 AM10/16/96
to

Sajal Kumar <saj...@clientlink.com> writes: > Boistuaud Frederic wrote:
> >
> > Hi folks,
> >
> > I'm using SQLSErver6.0 with VB4/16 & ODBC. (DAO level)
> >
> > Can anyone tell me how to trap the error Number generated by SQLServer
> > if a call fails (Eg: Attempt to insert null into a column that does not
> > allow null)
> > It returns: "ODBC Call failed, Error 3146".
> > I would like it to return : "Msg 515, Level 16, State 3
> > Attempt to insert the value NULL into column 'C1', table
> > 'StaffDev.dbo.frdTest'; column does not allow nulls. INSERT fails.
> > Command has been aborted." or at least just the error & State Number
> >
> > --
> > Frédéric.
> i am surprised that you are only getting the first message that ODBC
> call failed and not the Msg 515.... part. vb3 use to return ODBC call
> failed message along with the one spit out by the server.
> thanx.
> sajal.

U can indeed get the complete message displayed as follows:

Use DBEngine.Errors(0).Number to display the actual error number...and
use DBEngine.Errors(0).Description to display the actual message.

This we are using and is working fine.

Bye,

Maruthi.

Bill Bartlett

unread,
Oct 16, 1996, 3:00:00 AM10/16/96
to

"Boistuaud Frederic" <fr...@macmillan.co.uk> wrote:

If you're using DAO, loop thru the DBEngine.Errors collection -- it
has the details of the errors. (DBEngine.Errors(0) has the 3146
error, but .Errors(1) thru (n) has the more detailed stuff.)

Steven Daniels

unread,
Oct 18, 1996, 3:00:00 AM10/18/96
to

Maruthi Kaza <k...@wipsys.stph.net> wrote:

>Sajal Kumar <saj...@clientlink.com> writes: > Boistuaud Frederic wrote:
>> >

>> > Hi folks,
>> >
>> > I'm using SQLSErver6.0 with VB4/16 & ODBC. (DAO level)
>> >
>> > Can anyone tell me how to trap the error Number generated by SQLServer
>> > if a call fails (Eg: Attempt to insert null into a column that does not
>> > allow null)
>> > It returns: "ODBC Call failed, Error 3146".
>> > I would like it to return : "Msg 515, Level 16, State 3
>> > Attempt to insert the value NULL into column 'C1', table
>> > 'StaffDev.dbo.frdTest'; column does not allow nulls. INSERT fails.
>> > Command has been aborted." or at least just the error & State Number
>> >
>> > --
>> > Frédéric.

>> i am surprised that you are only getting the first message that ODBC
>> call failed and not the Msg 515.... part. vb3 use to return ODBC call
>> failed message along with the one spit out by the server.
>> thanx.
>> sajal.

>U can indeed get the complete message displayed as follows:

>Use DBEngine.Errors(0).Number to display the actual error number...and
>use DBEngine.Errors(0).Description to display the actual message.

>This we are using and is working fine.

>Bye,

>Maruthi.

Dim objErr as Error
Dim strMsg as String
Dim intErr as Long

For Each objErr in Errors
strMsg = strMsg & "<" & CStr(objErr.Number) & ">"
strMsg = strMsg & objErr.Description & vbCrLf
Next

intErr = Err.Number
Err.Raise intErr, , strMsg

This will return one messagebox with a header of Error: 3146
followed by each ODBC error number and description with a linefeed
between error listed. Useful in ole server situation.
Steve Daniels ste...@ptdprolog.net


0 new messages