public void PersistenceExceptionCtorTest()
		{
			PersistenceException perex = new PersistenceException();
			Assert.IsNotNull(perex, "C1#1");

			string msg = Guid.NewGuid().ToString();
			perex = new PersistenceException(msg);
			Assert.AreEqual(msg, perex.Message, "C1#2");

			perex = null;
			msg = Guid.NewGuid().ToString();
			try
			{
				DivideBy0();
				Assert.Fail("C1#3");
			}
			catch(Exception ex)
			{
				perex = new PersistenceException(msg, ex);
			}
			Assert.AreEqual(msg, perex.Message, "C1#4");
			Assert.IsTrue(perex.InnerException is DivideByZeroException, "C1#5");
			Assert.IsNull(perex.InnerException.InnerException, "C1#6");
			Assert.IsTrue(perex.GetBaseException() is DivideByZeroException, "C1#7");

			// TODO: deserialization
		}
        void IPendingWork.Commit(Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor accessor = null;

            try
            {
                accessor = new PersistenceDBAccessor(this._dbResourceAllocator, transaction, this._transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                    case PendingWorkItem.ItemType.Instance:
                        accessor.InsertInstanceState(item, this._serviceInstanceId, this.OwnershipTimeout);
                        break;

                    case PendingWorkItem.ItemType.CompletedScope:
                        accessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                        break;

                    case PendingWorkItem.ItemType.ActivationComplete:
                        accessor.ActivationComplete(item.InstanceId, this._serviceInstanceId);
                        break;
                    }
                }
            }
            catch (SqlException exception)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", new object[] { exception.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception.StackTrace });
                if (exception.Number == _deadlock)
                {
                    PersistenceException exception2 = new PersistenceException(exception.Message, exception);
                    throw exception2;
                }
                throw;
            }
            catch (Exception exception3)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", new object[] { exception3.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception3.StackTrace });
                throw exception3;
            }
            finally
            {
                if (accessor != null)
                {
                    accessor.Dispose();
                }
            }
        }
        void IPendingWork.Commit(Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor accessor = null;
            try
            {
                accessor = new PersistenceDBAccessor(this._dbResourceAllocator, transaction, this._transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                        case PendingWorkItem.ItemType.Instance:
                            accessor.InsertInstanceState(item, this._serviceInstanceId, this.OwnershipTimeout);
                            break;

                        case PendingWorkItem.ItemType.CompletedScope:
                            accessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                            break;

                        case PendingWorkItem.ItemType.ActivationComplete:
                            accessor.ActivationComplete(item.InstanceId, this._serviceInstanceId);
                            break;
                    }
                }
            }
            catch (SqlException exception)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", new object[] { exception.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception.StackTrace });
                if (exception.Number == _deadlock)
                {
                    PersistenceException exception2 = new PersistenceException(exception.Message, exception);
                    throw exception2;
                }
                throw;
            }
            catch (Exception exception3)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", new object[] { exception3.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception3.StackTrace });
                throw exception3;
            }
            finally
            {
                if (accessor != null)
                {
                    accessor.Dispose();
                }
            }
        }
        /// <summary>
        /// Commmit the work items using the transaction
        /// </summary>
        /// <param name="transaction"></param>        
        /// <param name="items"></param>
        void IPendingWork.Commit(System.Transactions.Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor persistenceDBAccessor = null;
            try
            {
                persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, transaction, _transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                        case PendingWorkItem.ItemType.Instance:
                            persistenceDBAccessor.InsertInstanceState(item, _serviceInstanceId, OwnershipTimeout);
                            break;

                        case PendingWorkItem.ItemType.CompletedScope:
                            persistenceDBAccessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                            break;

                        case PendingWorkItem.ItemType.ActivationComplete:
                            persistenceDBAccessor.ActivationComplete(item.InstanceId, _serviceInstanceId);
                            break;

                        default:
                            Debug.Assert(false, "Committing unknown pending work item type in SqlPersistenceService.Commit()");
                            break;
                    }

                }
            }
            catch (SqlException se)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", se.Message, _serviceInstanceId.ToString());
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", se.StackTrace);

                if (se.Number == _deadlock)
                {
                    PersistenceException pe = new PersistenceException(se.Message, se);
                    throw pe;
                }
                else
                {
                    throw;
                }

            }
            catch (Exception e)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", e.Message, _serviceInstanceId.ToString());
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", e.StackTrace);
                throw e;
            }
            finally
            {
                if (persistenceDBAccessor != null)
                    persistenceDBAccessor.Dispose();
            }
        }