MirjanaBojanic123
Programmer
I am using transactions in wcf, and I have one question. Transaction works fine when I work with database, it rollbacks all changes made in database if all commands are not completed.
But when I work with files, there is one problem. I want to copy few files in the computer, and to do some inputs into database. If all operations are not completed, I want to rollback all files that have been copied on the machine (In this case it would be deleting pasted files).
But, in mu case, operatins made on database are rollbaced, but files are still saved on machine, there is no mechanisam which automaclly deletes them.
Here is the code I use for transactions:
Using theScope As TransactionScope = New TransactionScope(TransactionScopeOption.Required)
Try
Dim tfc As New m_TransactedFile()
tfc.Copy("C:\Documents and Settings\Mirka\Desktop\From1.txt", "C:\Documents and Settings\Mirka\Desktop\To1.txt")
... (operations with database)
Dim tfc1 As New m_TransactedFile()
tfc1.Copy("C:\Documents and Settings\Mirka\Desktop\From2.txt", "C:\Documents and Settings\Mirka\Desktop\To2.txt")
theScope.Complete()
Catch ex As Exception
theScope.Dispose()
End Try
End Using
m_TransactedFile is user defined class, which Implements IEnlistmentNotification and ISinglePhaseNotification
If anyone knows about this problem, please write!
But when I work with files, there is one problem. I want to copy few files in the computer, and to do some inputs into database. If all operations are not completed, I want to rollback all files that have been copied on the machine (In this case it would be deleting pasted files).
But, in mu case, operatins made on database are rollbaced, but files are still saved on machine, there is no mechanisam which automaclly deletes them.
Here is the code I use for transactions:
Using theScope As TransactionScope = New TransactionScope(TransactionScopeOption.Required)
Try
Dim tfc As New m_TransactedFile()
tfc.Copy("C:\Documents and Settings\Mirka\Desktop\From1.txt", "C:\Documents and Settings\Mirka\Desktop\To1.txt")
... (operations with database)
Dim tfc1 As New m_TransactedFile()
tfc1.Copy("C:\Documents and Settings\Mirka\Desktop\From2.txt", "C:\Documents and Settings\Mirka\Desktop\To2.txt")
theScope.Complete()
Catch ex As Exception
theScope.Dispose()
End Try
End Using
m_TransactedFile is user defined class, which Implements IEnlistmentNotification and ISinglePhaseNotification
If anyone knows about this problem, please write!