July 11, 2008 at 9:58 am
I am using following code to implement try n catch in sql server 2005. But its giving me error of "Invalid syntax near TRY".....is there some thing i m doin wrong?
BEGIN TRY
BEGIN TRANSACTION
INSERT Funds VALUES (10)
INSERT Funds VALUES (-1)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
July 11, 2008 at 10:05 am
it parses fine for me,
is this the whole query?
July 11, 2008 at 10:07 am
yes this is the whole query.
Do i have to enable exception handling?
coz in my Query window.......TRY & CATCH are not being shown as Reserved words.
July 11, 2008 at 10:12 am
you dont have to enable it, TRY should turn blue once you have typed it in SMSS, unless you are using 2k then it won't work at all
July 11, 2008 at 10:15 am
I am using sql server 2005 Developer Edition. TRY & Catch are not truning into BLUE (Reserved Words).
By the way i am running it as an anynomas blocks...could dat be a problem?
Should i use it in a procedure?
July 11, 2008 at 10:26 am
By the way i am running it as an anynomas blocks...could dat be a problem?
Should i use it in a procedure?
I think anyomous blocks are an ORACLE term, i have never heard of it in SQL. I may be wrong though.
This should be run as a procedure, also the query does not look like it would run anyway.
is Funds a column in a table?
if so you need to tell the query what table to insert the data into.
July 11, 2008 at 10:34 am
Anynomas block means running the query in SSMS...not within a procedure or function.
i have tried it as follows now....but its still now working......p.s Funds is the name of the table
create proc abc
as
begin
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO Funds VALUES (10)
INSERT INTO Funds VALUES (-1)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
end
July 11, 2008 at 10:37 am
Thanks, i havent heard that term before...
The query works fine for me and inserts two rows into the table.
July 11, 2008 at 10:40 am
HI There,
What compatability mode are you in 80 or 90?
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
July 11, 2008 at 10:42 am
sorry one more question might be a silly one.
What console are you using?
e.g. SSMS or Query Analyser etc?
Thanks
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
July 11, 2008 at 10:45 am
One last thing this can be run as a block and will work , it should not have to be in a Procedure...
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
July 11, 2008 at 12:43 pm
Sounds like a client side issue. If you are using SMSS, do you have Tools > Options > Scripting > "Script for server Version" ... make sure its set to SQL Server 2005. I'm not sure waht else the setting would be good for.
July 11, 2008 at 1:55 pm
There is no option to activate/deactivate Try/Catch in SQL 2005.
Right-click on the database in Management Studio, select Properties, go to the Options tab, there will be a line on there that says what compatibility level you are running in. If it says "80" instead of "90", you will not be able to use any of the SQL 2005 features, including Try/Catch, in that database.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 15 posts - 1 through 15 (of 18 total)
You must be logged in to reply to this topic. Login to reply