Error handling in SQL Server

Hi All,

Please consider below code.
Msg 2714, Level 16, State 6, Procedure P_CreateSampleTable, Line 93
There is already an object named 'sampletable' in the database.

Open in new window


for retrieivng the errornumber and state we can use ERROR_NUMBER(), ERROR_STATE() etc.
What should be used to retrieve the object where error is reported from in this case "Procedure P_CreateSampleTable".

Also line no doesn't seem to exactly represent the source of error. Regret if this is too trivial. Any inputs are appreciated.
JyozealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
ERROR_PROCEDURE() returns the object and ERROR_LINE() the line where the error fired.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JyozealAuthor Commented:
Thanks. When i use ERROR_LINE() the line no given by SQL Server is differing from the line no where actually the error is. Any idea why this is happening?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Need to see your code but probably you have GO statements. If so, that resets the line numbers. Check if the line number isn't the number of lines from the last GO in your code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.