none
EnterpriseLibrary 3.0 with .NET Transaction (WCF) RRS feed

  • Question

  •  

    Hi,

    I have a requirement where I need to insert multiple records into database and the same time I wants to retrieve from database within the single transaction. The following sample is created for testing. It gives deadlock, transaction abort exception. Please address any issue in this code.

     

    My actual business requirement is, multiple clients send files as message chunks to WCF service (transport protocol is MSMQ), the WCF service assemble the message chunk in its channel stack and send full file to service method. Where the WCF service enabled transaction (Transaction scop enabled) and it is using chunking channel in its channel stack. Further this message chunks are persisted into database layer and again retrieve from database for assembling.

     

    Please advice me.

     

    private void button1_Click(object sender, EventArgs e)

    {

    ThreadPool.QueueUserWorkItem(new WaitCallback(ShowSomeText), "1");

    ThreadPool.QueueUserWorkItem(new WaitCallback(ShowSomeText), "2");

    ThreadPool.QueueUserWorkItem(new WaitCallback(ShowSomeText), "3");

    ThreadPool.QueueUserWorkItem(new WaitCallback(ShowSomeText), "4");

    ThreadPool.QueueUserWorkItem(new WaitCallback(ShowSomeText), "5");

    }

     

    private void ShowSomeText(object state)

    {

    try

    {

    using (TransactionScope scop = new TransactionScope(TransactionScopeOption.RequiresNew))

    {

    Database database = DatabaseFactory.CreateDatabase();

    for (int ind = 0; ind < 100; ind++)

    {

    //Initialize Database access

    DbCommand commandWrapper = database.GetStoredProcCommand(

    "AddMessageInfo");

    database.AddInParameter(commandWrapper, "@ChannelId", DbType.String,

    ind.ToString());

    database.AddInParameter(commandWrapper, "@SequenceNo", DbType.Int32,

    ind);

    database.AddInParameter(commandWrapper, "@Message", DbType.String,

    ind.ToString());

    database.ExecuteNonQuery(commandWrapper);

    }

    for (int ind = 0; ind < 100; ind++)

    {

    DbCommand commandWrapper = database.GetStoredProcCommand(

    "GetCompletedMessageInfo");

    database.AddInParameter(commandWrapper, "@ChannelId", DbType.String,

    ind.ToString());

    database.AddInParameter(commandWrapper, "@SequenceNo", DbType.Int32,

    ind);

    DataSet ds = new DataSet();

    database.LoadDataSet(commandWrapper, ds, "TestTable");

    }

    scop.Complete();

    }

    }

    catch (Exception ex)

    {

    MessageBox.Show(ex.Message);

    }

    }

     

    Thanks

     

    Ansii

    Tuesday, July 17, 2007 5:11 AM