sql server - SQL Transaction not working -


i using below sql delete records , insert customers table inside transaction. if there error in insert statements, seeing error message , when try execute select * customers, not displaying result set. , when close ssms window, showing there uncommitted transactions. wish commit these transactions before closing window?

after click ok, results getting displayed table. so, there locking mechanism taking place while using transaction.

use cmsdb; begin try     begin tran t1;          delete customers         print @@trancount -->prints 3 since there 3 records         insert customers         insert customerd --> error here         insert customers      commit tran t1; end try begin catch      print 'hi' --> not printing     select @@trancount --> not resulting     if @@trancount > 0          rollback tran t1;     -- error message     declare @err nvarchar(1000)     set @err = error_message()     raiserror (@err,16,1) end catch go 

message

(3 row(s) affected)  (1 row(s) affected)  (1 row(s) affected)  (1 row(s) affected) msg 208, level 16, state 1, line 8 invalid object name 'dbo.customerd'. 

excerpt try…catch description:

the following types of errors not handled catch block when occur @ same level of execution try…catch construct:

  • compile errors, such syntax errors, prevent batch running.

  • errors occur during statement-level recompilation, such object name resolution errors occur after compilation because of deferred name resolution.

in case happens is

the error not caught , control passes out of try…catch construct next higher level.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -