Subsonic Transaction Error

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

Upvotes: 1

Views: 1868

Answers (6)

aboutme
aboutme

Reputation: 245

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.

Upvotes: 0

user1151
user1151

Reputation:

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

Upvotes: 1

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.

Upvotes: 0

Chris
Chris

Reputation: 28064

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

Upvotes: 0

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.

Upvotes: 0

runxc1 Bret Ferrier
runxc1 Bret Ferrier

Reputation: 8233

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

Upvotes: 0

Related Questions