Question : Executing a SP with temp tables from another SP

I am having some trouble with Stored Procs. I have a couple of SPs say caller and called. The caller SP calls the called SP which returns a value. This scenario works fine as long as the called SP does not make use of any temp tables. When I use temp tables in the called SP, I get the following error&

There was a transaction active when exiting the stored procedure 'called'. The temporary table '#tmp_tbl' was dropped in this transaction either explicitly or implicitly. This transaction has been aborted to prevent database corruption.

Does anyone have any idea?

Answer : Executing a SP with temp tables from another SP

The #tmp_tbl is currently being dropped as you exit CALLED because it only lives for the life of the stored procedure execution.  As you have found out, Sybase does not want you to drop a temp table in the context of a transaction.  I think part of the issue is that, if you roll back a transaction that modifies the system tables, you could leave things in a bad way.  Maybe someone else has a more explicit explanation for what they are trying to avoid.

That said, you have a couple of choices.
1)  You can create the #tmp_tbl in the CALLER and use it in the CALLED.  This gets around the problem of temp table scope.  Of course, if you are doing transaction control outside the CALLER SP, you have not really solved the problem.
2)  You can modify the explicit transaction control to encompass less of the SP code and make sure the temp table drop is happening outside of that window.

Hopefully you are using explicity transaction control and not leaving it up to the system.  Is the transaction control done inside the CALLER SP?

Also, what transaction isolation level are you running?

Regards,
Bill
Random Solutions  
 
programming4us programming4us