Wednesday, March 28, 2012

Print and Raiserror

I wanted to give user message from SQL Stored Procedure.
I tried to use PRINT, but it does not go to my MS Access front end
application
I tried to use 'RAISERROR' to send out message, but the message has SQL
server message to my MS Access.
Are there any way to sent message to my front end application user form
stored procedure?
Any information is great appreciated.
Souris,souris wrote:
> I wanted to give user message from SQL Stored Procedure.
> I tried to use PRINT, but it does not go to my MS Access front end
> application
> I tried to use 'RAISERROR' to send out message, but the message has
> SQL server message to my MS Access.
> Are there any way to sent message to my front end application user
> form stored procedure?
> Any information is great appreciated.
> Souris,
You can use RAISERROR. Please post you code to generate the error and
exactly the problem you are seeing with using it. I assume you want to
notify the client app about an error condition and not just a normal
message. Is that correct?
For example, you could use:
RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
or
RAISERROR ('The level for job_id:%d should be between %d and %d.', 16,
1, @.@.JOB_ID, @.@.MIN_LVL, @.@.MAX_LVL)
David Gugick
Imceda Software
www.imceda.com|||Thanks for the message.
Here is my SQL
BEGIN
RAISERROR('YOU HAVE UPDATE DATA TODAY, IF YOU THINK YOU NEED UPLOAD ONE
MORE TIME PLEASE SEE YOUR ADMINISTRATOR, THANKS', 16, -1)
RETURN
END
The message comes following form my Access front end
Microsoft Access
ODBC - call failer
[Microsoft][ODBC SQL server Driver][SQL Driver]YOU AHVE UPDATE DATA TODAY,
OF YOU THINK YOU NEED UPLOAD ONE MORE TIME PLEASE SEE YOUR ADMINISTARTOR,
THANKS(#50000) [Microsoft][ODBC driver SQL Server][SQL server] Violation of
PRIMARY KEY constaint 'PK_TSC_CMPLD_CALLOUTS', Cannot insert duplicate key
in object 'TSC_CMPLD_CALLOUTS'. (#2627)Microsoft][ODBC SQL server
Driver][SQL Driver]The statement has been terminated.(#3621)[ODBC driver SQL
Server][SQL server] Violation of PRIMARY KEY constaint
'PK_TSC_CMPLD_CALLOUTS', Cannot insert duplicate key in object
'TSC_CMPLD_CALLOUTS'. (#2627)Microsoft][ODBC SQL server Driver][SQL
Driver]The statement has been terminated.(#3621)
How can I give the user message from my stored procedure?
Why my Access front give so much message to user?
Any information is great appreciated.
Thanks again,
Souris,
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:%23OSTKNfJFHA.1308@.TK2MSFTNGP15.phx.gbl...
> souris wrote:
> You can use RAISERROR. Please post you code to generate the error and
> exactly the problem you are seeing with using it. I assume you want to
> notify the client app about an error condition and not just a normal
> message. Is that correct?
>
> For example, you could use:
> RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
> or
> RAISERROR ('The level for job_id:%d should be between %d and %d.', 16, 1,
> @.@.JOB_ID, @.@.MIN_LVL, @.@.MAX_LVL)
>
>
> --
> David Gugick
> Imceda Software
> www.imceda.com|||souris wrote:
> Thanks for the message.
> Here is my SQL
> BEGIN
> RAISERROR('YOU HAVE UPDATE DATA TODAY, IF YOU THINK YOU NEED UPLOAD
> ONE MORE TIME PLEASE SEE YOUR ADMINISTRATOR, THANKS', 16, -1)
> RETURN
> END
Sounds like you are generating a lot of errors in whatever SQL you are
running. Try running the SQL with the same parameter values from Query
Analyzer or some other query tool (probably can use Access as well) and
make sure it doesn't generate any errors.
It looks like you are using RAISERROR to return a message. RAISERROR is
for raising errors only, not for messages. I would have the application
display the message on it's own, and not have it generated from the
database.
David Gugick
Imceda Software
www.imceda.com|||Thanks for the message.
My App needs download once and only once per day
The date filed is a part of my primary key.
I wanted to use RAISERROR to raise error and also let user know what
happens.
1. If I use RAISERROR the SQL statement should not continue executing the
rest of SQL, but it seems continues running to violate primary key rule.
2. If I need to write message on front end application then there must be a
way to get rid the [Microsoft ODBC][SQL Server] message from RAISERROR.
Your information is great appreciated
Souris,
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:OTuFBvyJFHA.3552@.TK2MSFTNGP12.phx.gbl...
> souris wrote:
> Sounds like you are generating a lot of errors in whatever SQL you are
> running. Try running the SQL with the same parameter values from Query
> Analyzer or some other query tool (probably can use Access as well) and
> make sure it doesn't generate any errors.
> It looks like you are using RAISERROR to return a message. RAISERROR is
> for raising errors only, not for messages. I would have the application
> display the message on it's own, and not have it generated from the
> database.
> --
> David Gugick
> Imceda Software
> www.imceda.com|||souris wrote:
> Thanks for the message.
> My App needs download once and only once per day
> The date filed is a part of my primary key.
> I wanted to use RAISERROR to raise error and also let user know what
> happens.
> 1. If I use RAISERROR the SQL statement should not continue executing
> the rest of SQL, but it seems continues running to violate primary
> key rule.
> 2. If I need to write message on front end application then there
> must be a way to get rid the [Microsoft ODBC][SQL Server] message
> from RAISERROR.
It looks like the snippet of code you posted should work. You are using
raiserror in a block with a return statement (you should add a return
code). I don't see how the rest of the SQL is being executed unless it
occurred before the raiserror. Can you post the entire procedure?
David Gugick
Imceda Software
www.imceda.com

No comments:

Post a Comment