python - Trouble with "IF @@TRANCOUNT > 0 COMMIT TRAN" -


i'm building flask application sqlalchemy query , sql server database storage. noticed in sql server activity monitor there lot of open sessions this:

capture

i did search , not able find reason. wonder if know what's causing issue?

note: background, requests managed directly under flask context seem ok(so clicking around on website , running query not cause this). happens when run backend celery task.

is possible caused code structure?

this how defined session connection(use scoped_session):

engine = create_engine('connection string here') db_session = scoped_session(sessionmaker(autocommit=false, autoflush=false, bind=engine)) base = declarative_base() base.query = db_session.query_property() 

any appreciated, thanks!

i think happening in application , have written code ....

begin transaction    -- code here    if @@trancount > 0   begin    commit transaction;  end 

but if code after have opened transaction has not affected rows?

you have not committed it, makes sense since there no change commit have left open transaction.

you code should this...

begin transaction    -- code here    if @@trancount > 0   begin    commit transaction;  end else  begin    rollback transaction;  end 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -