views:

848

answers:

7

Considering the following code:

        List<Processo> listaProcesso = new List<Processo>();

        Processo processo;

        processo = new Processo();
        processo.AgendamentoID = 9;
        processo.DataEntrada = DateTime.Now;
        processo.EtapaExecucao = 0;
        processo.RegistrosAfetados = 2;
        listaProcesso.Add(processo);

        processo = new Processo();
        processo.AgendamentoID = 9;
        processo.DataEntrada = DateTime.Now;
        processo.EtapaExecucao = 0;
        processo.RegistrosAfetados = 1;
        listaProcesso.Add(processo);


        using (TransactionScope ts = new TransactionScope())
        {
            using (SharedDbConnectionScope scs = new SharedDbConnectionScope())
            {
                foreach (Processo processoSave in listaProcesso)
                {
                    processoSave.Save();
                }
            }
            ts.Complete();
        }

I can't see any error. But, when the save() is called for the second time, I receive a MySqlException: There is already an open DataReader associated with this Connection which must be closed first. Im am using Subsonic 3.0.0.3 and MySql.Data 6.0.4.0.

Thanks in advance.

Carlos Eduardo Appel Klein

A: 

Hmmm, by the looks of the error I would assume that elsewhere in your application you are using a DataReader/IDataReader and did not Dispose of it before saving all of your "processo" records.

You also need to re-order your using statements as the TransactionScope needs to be on the inside. For a code snippet on how to perform what you are trying to do above you need to look at SubSonic Transaction link

runxc1 Bret Ferrier
A: 

This piece of code is the application, there are no others calls. I built to simulate this error. I changed the order of using, but the error continues.

Thanks.

A: 

Also, you should be using a ProcessoCollection rather than a list. In the loop, add your items to the collection then call myCollection.BatchSave();

Chris
A: 

I could be wrong, but I think the command BatchSave () does not exist in SubSonic 3.0.

Forgot to mention that I am using the ActiveRecord templates.

+1  A: 

Your best bet here is to use a BatchQuery: http://subsonicproject.com/docs/BatchQuery

Rob Conery
A: 

im facing the same problem. The problem is internal to subsonic. I dont use any data readers. Its some sort of race condition using saves that happen one after another quickly accross different objects.

skiik
A: 

Ive found a solution to this problem.

Go download the latest subsonic source code and compile it yourself. The bug appears to be in the subsonic code and a fix has been applied to the latest codebase.

skiik