If any of the steps fail, the whole transaction should rollback even the database creation. But when I am using transaction property on Create database, it is throwing an exception
CREATE DATABASE statement not allowed within multi-statement transaction.
Is there any method to achieve the same instead of delete database command.(i.e programmitically delete the database)
I'm afraid you can't.
From the MSDN documentation:
The CREATE DATABASE statement must run in autocommit mode (the default transaction management mode) and is not allowed in an explicit or implicit transaction.
No, it's not possible. CREATE DATABASE:
The CREATE DATABASE statement must run in autocommit mode (the default transaction management mode) and is not allowed in an explicit or implicit transaction.
So you'll have to explicitly check at the end and issue a DROP DATABASE to clean up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With