Hi.
I have a problem with transaction using SQL Compact when using BatchProccess.
Has we all know that SQL Compact does not support nested transaction, but the BatchProcess always creates a new transaction making it impossible to set transaction on the first level.
Is there any way to tell the BatchProcess or the DataAccessAdapter that there exists a transaction, and in return do not create a transaction of there own ??
This is what I like to do, where the services use database components descried below.
using (TransactionScope scope = new TransactionScope())
{
myFirstService.Save(listofStuffToSave);
mySecondService.Save(anotherListOfStuffToSave);
scope.Complete();
}
Here is our code that does the commit to the database from within a abstract base database component.
/// <summary>
/// Commit save list and delete list.
/// </summary>
/// <param name="saveList">List of entites to save</param>
/// <param name="deleteList">List of entites to delete</param>
/// <returns></returns>
public int Save(EntityCollection<CommonEntityBase> saveList, EntityCollection<CommonEntityBase> deleteList)
{
Logger.Debug("Save");
int numberChanged = 0;
try
{
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
BatchProcess batchProcess = new BatchProcess();
batchProcess.CollectionsToSave = saveList;
batchProcess.CollectionsToDelete = deleteList;
numberChanged = batchProcess.Commit(adapter);
}
}
catch (Exception ex)
{
Logger.Error("Save: Exception", ex);
IExceptionMapping exMapping = ExceptionMappingFactory.GetMapper<IExceptionMapping>();
exMapping.HandleDalException(ex);
}
return numberChanged;
}
if we use this code for SQL Compact scenario we get 'The connection object can not be enlisted in transaction scope.' .
It seams that the adapter already knows that there exists a System Transaction from the property InSystemTransaction is set to true, when transaction have been created.
We are setting SqlServerDQECompatibilityLevel = 4 from the app.config.
I thought that that would be enough, but the DataAccessAdapter still has the CompatibilityLevel as null.
We are using the same components for Oracle and SQL Server (Compact as well), just be switching out the DalDBSpecific assemblies, works like a charm, except for transaction scenarios for SQL Compact.
llbgen Version:
ORMSupportClasses.NET20 3.1.11.0518
DQE.SqlServer.NET20 3.1.11.0221
So in short,
Is there a way to force the BatchProcess not to create a transaction when in System Transaction , so that we don't get nested transactions ??
solution is needed !!
best regards
thorri.