RE: How to have SQL_ERROR returned from RAISERROR within IF-BLOCK
- From: Pak-Ming Cheung [MSFT] <PakMingCheungMSFT@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 9 Aug 2008 09:31:01 -0700
Could you try the SQL Native Client?
Thanks,
Ming.
"M. Shoaib Surya" wrote:
Hi.
I am using MS SQL Server 2000.
I want to return SQL_ERROR to my application with a custom error message
from ODBC.
From what I could find form the documentation, RAISERROR statement with
severity of 11 or more is the way for me to go.
I get it returned fine when I execute the following statement using
SQLExecDirect:
RAISERROR('My error message', 11, 1)
But it returns SQL_SUCCESS_WITH_INFO rather than SQL_ERROR when I put the
RAISERROR statement within an IF-block and execute it as follows:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('dbo.my_table')
AND OBJECTPROPERTY(id, 'IsUserTable') = 1)
RAISERROR('My error message', 11, 1)
From what I could find in the forums makes me understand that this happens
because I am executing a batch of statements and in this case ODBC would
return SQL_SUCCESS_WITH_INFO. But I am using a wrapper library over ODBC and
I must have SQL_ERROR returned from SQLExecDirect. My main requirement is to
have SQL_ERROR returned with with a custom error message if some particular
table exists in the database. Can anyone give me any suggestions or
solutions to help achieve this thing?
Thanks in advance
Regards,
Shoaib.
- Follow-Ups:
- Re: How to have SQL_ERROR returned from RAISERROR within IF-BLOCK
- From: M. Shoaib Surya
- Re: How to have SQL_ERROR returned from RAISERROR within IF-BLOCK
- Prev by Date: RE: ODBC fails from Windows Service in VS.Net 2008
- Next by Date: RE: Unicode ODBC Driver development
- Previous by thread: ODBC fails from Windows Service in VS.Net 2008
- Next by thread: Re: How to have SQL_ERROR returned from RAISERROR within IF-BLOCK
- Index(es):
Loading