Sqlserver Error Messages

General discussion forum about all databases other than SqlBase.
FRBhote
India
Posts: 2220
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Sqlserver Error Messages

Post by FRBhote » 08 Apr 2021, 08:30

When there is an Sql error, then the error message is got by SqlGetErrorText( nError, strMessage )

However on some installation strMessage is got and on some it is not got.

What should be done to get this error message on all installations?

TIA

Michael Ehehalt
Germany
Posts: 73
Joined: 13 Mar 2017, 09:17
Location: Frankfurt, Germany

Re: Sqlserver Error Messages

Post by Michael Ehehalt » 08 Apr 2021, 14:30

Hi FRBhote,

I've found this in the SqlGetErrorText documentation:

When connected to an OLE DB data source, do not use this function; use SqlGetSessionErrorInfo instead.

Do you use OLE DB? ... just an idea ...

Regards Michael
Best regards,
Michael Ehehalt

FRBhote
India
Posts: 2220
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: Sqlserver Error Messages

Post by FRBhote » 09 Apr 2021, 05:15

Unfortunately we use ODBC.

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 450
Joined: 05 Mar 2017, 20:57
Location: Stroud, England <--> Tauranga, New Zealand

Re: Sqlserver Error Messages

Post by Steve Leighton » 10 Apr 2021, 00:25

.
Have really only ever used OLEDB with SS, but I believe that
'SqlGetErrorText()' returns the error number found in ERROR.sql ( which is SQLBase errors ).

If you only get the error text on some installations - then maybe ERROR.sql is missing from the client ( or the error code is not found in ERROR.sql ).

Maybe try using SqlGetError() in its place, which will turn off error 'mapping' and return the true backend error ( and its actual message Text ).
You can optionally trap only the error codes you want of course.
This is only my theory - as don't use ODBC, but worth a simple try to bypass 'ERROR.sql'
e.g.

Code: Select all

If SqlGetError( hpSqlHandle, nError, sTemp )
	If TcsIsSqlServer( hpSqlHandle )
		Loop
			Set nChar = SalStrLop( sTemp )
			If Not nChar
				Break
			Set sError = sError || SalNumberToChar( nChar )
		!
		Set sError = VisStrSubstitute( sError, '[Microsoft][ODBC SQL Server Driver][SQL Server]', ' - ' )
		!
		Select Case nError
			Case 20030
				If SalStrScan( sError, '2601' ) > -1
					Set nError = SqlErr_UniqueDataRequired
				Else If SalStrScan( sError, '2627' ) > -1
					Set nError = SqlErr_UniqueDataRequired
				Else
					Set nError = SqlErr_UnmatchedForeignKey
				Break
			Case 20050
				Set nError = SqlErr_TableNotCreated
				Break
			Case 20054
				Set nError = SqlErr_InvalidColumnName
				Break
			Default
				! Do nothing as we don't recognise the error
		!
		Set srpError = sError
	Else
		Set srpError = sTemp
	Set nrpError = nError
	Return TRUE
Return FALSE
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 12 guests