How To Capture Error Message In Sybase
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Get System Error Message In Sybase up vote 1 down vote favorite I am writing a procedure and doing error handling after each step. If an error comes, I return an error code with custom user friendly error message. But due to some requirement, I also have to pass system error message. Sample : Ex: I am inserting some records into table and if something goes wrong , I have error message to handle it. Insert into A Select top 250 id from C inner join D on c.id = D. id IF (@@error != 0) BEGIN SELECT @p_err_code = 1 SELECT @p_err_desc = "Error while inserting records into #PAR_PROVIDERS." <---------- how to pass system error message here--------> DROP TABLE #PAR_PROVIDERS RETURN 1 END sybase-ase share|improve this question edited May 22 '15 at 13:36 Parado 19.1k73161 asked May 22 '15 at 8:53 Praveenks 3761925 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted I don't know how to take specify error message - I think it's not possible. Maybe below query will cover your needs. It return and pattern message for example Must declare variable '%.*s'. insetad of Must declare variable 'fake variable'. SELECT description from master..sysmessages where error = @@error @@error variable change every time you make an operation so you need to use local variable for example @err. In your code should be like this. declare @err
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > Sybase error text Want to Advertise Here? Solved Sybase error text Posted on 2011-01-31 Sybase Database 1 Verified Solution 7 Comments 1,495 Views Last Modified: 2012-06-21 How does one get a coresponding message text from @@error variable. I want to capture this in either a stored procedure or a batch file 0 Question by:4Learning Facebook Twitter http://stackoverflow.com/questions/30392366/get-system-error-message-in-sybase LinkedIn Google LVL 13 Best Solution byalpmoon I agree you can in that way. Also you can use a variable to store the error message: declare @msgtext varchar(1024), @err int -- your actual statement will be here select @err = Go to Solution 7 Comments LVL 13 Overall: Level 13 Sybase Database 12 Message Expert Comment by:alpmoon2011-01-31 I think the easiest way is just selecting description column from sysmessages table in master db: select * from https://www.experts-exchange.com/questions/26784570/Sybase-error-text.html master..sysmessages where error = xxx 0 Message Author Comment by:4Learning2011-01-31 Yes, but I need to write the messages to a log file in the following manner... insert into erro_log values(@@error, error_message) Well I dont think I can put in the select statement from sysmessages in the insert statement. Is there another way...? Thanks, 4learning 0 LVL 26 Overall: Level 26 Sybase Database 7 Message Expert Comment by:wilcoxon2011-01-31 Sure you can. insert into erro_log select error, description from master..sysmessages where error = @@error 0 LVL 13 Overall: Level 13 Sybase Database 12 Message Accepted Solution by:alpmoon2011-01-31 I agree you can in that way. Also you can use a variable to store the error message: declare @msgtext varchar(1024), @err int -- your actual statement will be here select @err = @@error if @err != 0 begin select @msgtext = description from master..sysmessages where error = @err insert into error_log values(@err, @msgtext ) end 0 Message Author Comment by:4Learning2011-01-31 Thankyou very much alpmoon. that helps! 0 LVL 26 Overall: Level 26 Sybase Database 7 Message Expert Comment by:wilcoxon2011-01-31 Why were full points awarded to alpmoon? His solution is less efficient and is just a modification of mine. 0 LVL 13 Overall: Level 13 Sybase Database 12 Message Expert Comment by:alpmoon2011-02-01 I think what I sugges
this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing http://www.dbforums.com/showthread.php?1660538-HELP!-How-to-get-the-error-text-within-a-Sybase-stored-proc messages, select the forum that you want to visit from the selection below. Results 1 http://www.perlmonks.org/?node_id=917760 to 8 of 8 Thread: HELP! How to get the error text within a Sybase stored proc? Tweet Thread Tools Show Printable Version Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 09-22-10,13:55 #1 zorrow View Profile View Forum Posts Registered User Join Date Sep 2010 Posts 4 how to Unanswered: HELP! How to get the error text within a Sybase stored proc? I want to read the error text (or message) from within a Sybase stored procedure. I have the value of @@error and I know you can find an entry for it in master..sysmessages, but what I want is the concrete error message. I mean, instead of the generic template for the message, such as: "SELECT INTO failed because column %d in table how to capture '%.*s' has a null column name. Null column names are not allowed." I would like to have the message associated to the actual error, which should rather look like this: "SELECT INTO failed because column 3 in table 'dbo.SOMETHING' has a null column name. Null column names are not allowed." I've been googling for hours and have found no solution so far. Is there any stored procedure I could call to get the message? Any log table? Any idea? Your help will be highly appreciated. Thanks a LOT in advance! Reply With Quote 09-22-10,14:13 #2 mike_bike_kite View Profile View Forum Posts Visit Homepage vaguely human Join Date Jun 2007 Location London Posts 2,527 Why not just go into the stored proc and supply a field name for each field in your select into statement? I can't see how the error message can be any clearer. If you fix the bug then you won't need to improve the message any further. Mike Reply With Quote 09-22-10,14:22 #3 zorrow View Profile View Forum Posts Registered User Join Date Sep 2010 Posts 4 Not a bad idea, but it would be quite painful doing this, statement after statement. After every statement which could possibly fail (and which are quite complex in my case), I already check for @@error, store it in a local va
Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Aug 01, 2011 at 05:50UTC ( #917760=perlquestion: print w/replies, xml ) Need Help?? puneet.keswani has asked for the wisdom of the Perl Monks concerning the following question: Hi.. I am stuck from quite some days now.. Here s the scenario I have a main perl script and a self designed perl module called common.pm, in the module I have writen 3 subroutenes, 1st to connect to Sybase, 2nd calling a sybase proc with parameters and 3rd disconnecting from Sybase.. in my main perl script I am using this module with the help of ; use common.pm From the main perl script I am calling the subroutenes to connect to database.. &common::sybaseconnection(parameters) Now my problem is that I want to capture the error message thrown by a database say when the password has expired and the connection cannot be made in the perl script so that I can log that message in a log file. The errors thrown by the databse can be seen as ouput on the screen but I am unable to capture those error meaasges in my main perl script.. These are simple error messages which database would throw incase it was supplied with wrong user id password. Please help !!Comment on Capturing error thrown by a database Replies are listed 'Best First'. Re: Capturing error thrown by a database by CountZero (Bishop) on Aug 01, 2011 at 06:20UTC It is difficult to be certain without having seen any of your code, but it looks as if you are printing your error messages, rather than returning them from your subroutine and saving them in a variable for further handling. CountZeroA program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James [reply][d/l][select] Re^2: Capturing error thrown by a database by puneet.keswani (Novi