What your code requires is Multiple Active Statement support (or as MS calls it MARS) as you have a cursor open (and outstanding rows unread) whilst trying to execute another statement (the alter). You have 2 choices. 1) as runrig suggests or 2) enable multiple active statement support (assuming your sql server driver and database support it. You can do the latter by adding MARS_Connection=yes to your connect string. For this simple case I believe you are better reorganizing your code and avoiding MARS as a) there are a few gotchas with MARS support and b) your script will be compatible with more ms sql servers.
UPDATE: There is a 3rd choice. Open 2 connections to the database.
In reply to Re: DBI DBD::ODBC, Create a table, drop its constraints, then recreate it again!
by mje
in thread DBI DBD::ODBC, Create a table, drop its constraints, then recreate it again!
by blackadder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |